Last active
December 26, 2015 12:48
-
-
Save whatalnk/eae8fbd6c8056374a620 to your computer and use it in GitHub Desktop.
yukicoderメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = gets.chomp.to_i | |
n = gets.chomp.to_i | |
w = gets.chomp.split(" ").map(&:to_i) | |
w.sort! | |
ww = 0 | |
i = 0 | |
w.each do |a| | |
ww += a | |
if ww > l then | |
break | |
end | |
i += 1 | |
end | |
puts i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = gets.chomp | |
alphabets = [("A".."Z").to_a, (0..25).to_a].transpose.to_h | |
res = "" | |
s.split("").each_with_index do |c, i| | |
res += alphabets.key((alphabets[c] - (i + 1)) % 26) | |
end | |
puts res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.21 平均の差 - yukicoder](http://yukicoder.me/problems/67) | |
n = gets.chomp.to_i | |
k = gets.chomp.to_i | |
nums = [] | |
n.times do | |
nums << gets.chomp.to_f | |
end | |
nums.sort! | |
nmax = nums.pop | |
nums.pop(k-2) | |
nmin = nmax | |
nums.size.times do | |
nmin = [nmin, nums.inject(:+) / nums.size].min | |
nums.pop | |
end | |
puts (nmax - nmin).round |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.22 括弧の対応 - yukicoder](http://yukicoder.me/problems/68) | |
n, k = gets.chomp.split(" ").map(&:to_i) | |
s = gets.chomp.split("") | |
left = [] | |
paren = {} | |
s.each_with_index do |i, j| | |
if i == "(" then | |
left << j+1 | |
else | |
paren[left.pop] = j+1 | |
end | |
end | |
if s[k-1] == "(" then | |
puts paren[k] | |
else | |
puts paren.key(k) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.24 数当てゲーム - yukicoder](http://yukicoder.me/problems/69) | |
n = gets.chomp.to_i | |
numbers = Array.new(10, 0) | |
n.times do | |
turn = gets.chomp.split(" ") | |
r = turn.pop | |
abcd = turn.map(&:to_i) | |
abcd.each do |i| | |
if r == "NO" | |
numbers[i] -= 1 | |
else | |
numbers[i] += 1 | |
end | |
end | |
end | |
puts numbers.index(numbers.max) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.29 パワーアップ - yukicoder](http://yukicoder.me/problems/1) | |
n = gets.chomp.to_i | |
items = Hash.new(0) | |
n.times do | |
gets.chomp.split(" ").map(&:to_i).each do |i| | |
items[i] += 1 | |
end | |
end | |
pu = 0 | |
pu1 = 0 | |
items.each do |k, v| | |
if v >= 2 then | |
p = v / 2 | |
pu += p | |
items[k] -= 2 * p | |
pu1 += items[k] | |
else | |
pu1 += v | |
end | |
end | |
puts pu + pu1/4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.32 貯金箱の憂鬱 - yukicoder](http://yukicoder.me/problems/5) | |
c100 = gets.chomp.to_i | |
c25 = gets.chomp.to_i | |
c1 = gets.chomp.to_i | |
c25 += c1 / 25 | |
c1 = c1 % 25 | |
c100 += c25 / 4 | |
c25 = c25 % 4 | |
c100 = c100 % 10 | |
puts c100 + c25 + c1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a, b = gets.chomp.split(" ").map(&:to_f) | |
puts (b / a).ceil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Math | |
n = gets.chomp.to_i | |
x = log2(n).floor | |
if 2**x == n then | |
puts x | |
else | |
puts x + 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.51 やる気の問題 - yukicoder](http://yukicoder.me/problems/100) | |
w = gets.chomp.to_i | |
d = gets.chomp.to_i | |
d.downto(2).each do |i| | |
w = w - w / (i * i) | |
end | |
puts w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d, p = gets.chomp.split(" ").map(&:to_i) | |
puts d + d * p / 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
m = gets.chomp.to_i | |
puts ((n / m) / 1000 ) * 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v1 = gets.chomp.split(".").map(&:to_i) | |
v2 = gets.chomp.split(".").map(&:to_i) | |
s1 = "" | |
v1.each do |i| | |
s1 += sprintf("%03d", i) | |
end | |
s2 = "" | |
v2.each do |i| | |
s2 += sprintf("%03d", i) | |
end | |
if s1.to_i >= s2.to_i then | |
puts "YES" | |
else | |
puts "NO" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = gets.chomp | |
puts s.swapcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
k = gets.chomp.to_i | |
s = gets.chomp.to_f | |
puts (s / (100 - k) * 100).to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
res = [] | |
flag = true | |
n.times do | |
x, y = gets.chomp.split(" ").map(&:to_i) | |
if y - x > 0 then | |
res << y - x | |
else | |
puts -1 | |
flag = false | |
break | |
end | |
end | |
if flag and res.uniq.length == 1 then | |
puts res[0] | |
else | |
puts -1 if flag | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
c = gets.chomp.split(" ").map(&:to_i) | |
a = c.inject(:+) / 10 | |
res = 0 | |
c.each do |cc| | |
if cc <= a then | |
res += 1 | |
end | |
end | |
p res * 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
is_break = false | |
(n-100..n+100).each do |i| | |
(2..i/2).each do |j| | |
if i % j == 0 then | |
puts i | |
is_break = true | |
break | |
end | |
end | |
break if is_break | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Math | |
s1 = gets.chomp | |
s2 = gets.chomp | |
s = (s1 + s2).split("") | |
res = 0 | |
holiday = 0 | |
s.each do |i| | |
if i == 'o' then | |
holiday += 1 | |
else | |
res = [res, holiday].max | |
holiday = 0 | |
end | |
end | |
puts [res, holiday].max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a, b = gets.chomp.split(" ").map(&:to_i) | |
res = [] | |
(a..b).each do |i| | |
if i % 3 == 0 then | |
res << i | |
elsif i.to_s.include?("3") then | |
res << i | |
end | |
end | |
puts res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.236 鴛鴦茶 - yukicoder](http://yukicoder.me/problems/592) | |
a, b, x, y = gets.chomp.split(" ").map(&:to_f) | |
r = [] | |
rx = x * b / a | |
if rx <= y then | |
r << x + rx | |
end | |
ry = y * a / b | |
if ry <= x then | |
r << ry + y | |
end | |
puts r.max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
res = Hash.new{0} | |
n.times do |i| | |
a = gets.chomp.split(" ") | |
n.times do |j| | |
if a[j] == "nyanpass" then | |
res[j] += 1 | |
end | |
end | |
end | |
if res.values.count(n-1) == 1 then | |
puts res.key(n-1) +1 | |
else | |
puts -1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = gets.chomp.to_i | |
puts x-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = gets.chomp.split("").sort.reverse | |
puts x.join("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, k = gets.chomp.split(" ") | |
if n == k then | |
puts "Drew" | |
elsif (n == "0" and k == "1") or (n == "1" and k == "2") or (n == "2" and k == "0") then | |
puts "Won" | |
else | |
puts "Lost" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = gets.chomp | |
if x == "0" then | |
puts 1 | |
else | |
puts 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
a = gets.chomp.split(" ").map(&:to_f) | |
a.sort! | |
if n % 2 == 0 then | |
puts (a[n/2 - 1] + a[n/2])/2 | |
else | |
puts a[n/2] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = gets.chomp | |
t = s.count("t") | |
r = s.count("r") | |
e = s.count("e")/2 | |
puts [t,r,e].min |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d = gets.chomp.to_i | |
res = d*108 | |
puts res.to_s.insert(-3, ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = gets.chomp.split("") | |
res = 0 | |
numbers = (1..9).to_a.map(&:to_s) | |
s.each do |i| | |
if numbers.include?(i) then | |
res += i.to_i | |
end | |
end | |
puts res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s, t, u = gets.chomp.split(" ") | |
s = s.split("") | |
t = t.to_i | |
u = u.to_i | |
if t < u then | |
s.delete_at(u) | |
s.delete_at(t) | |
elsif t > u then | |
s.delete_at(t) | |
s.delete_at(u) | |
else | |
s.delete_at(u) | |
end | |
puts s.join("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.296 n度寝 - yukicoder](http://yukicoder.me/problems/822) | |
n, h, m, t = gets.chomp.split(" ").map(&:to_i) | |
tt = (n - 1) * t | |
hh = tt / 60 | |
mm = tt % 60 | |
h = (h + hh + (m + mm) / 60) % 24 | |
m = (m + mm) % 60 | |
puts h | |
puts m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.299 蟻本が読めない - yukicoder](http://yukicoder.me/problems/808) | |
n = gets.chomp.to_i | |
a = 316 | |
b = 52 | |
puts a + (n-1)*b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [No.311 z in FizzBuzzString - yukicoder](http://yukicoder.me/problems/848) | |
n = gets.chomp.to_i | |
n15 = n / 15 | |
n3 = n / 3 | |
n5 = n / 5 | |
puts (n3 + n5 - n15) * 2 + n15 * 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment