Skip to content

Instantly share code, notes, and snippets.

@pwittchen

pwittchen/addrev.rb

Last active Dec 11, 2015
Embed
What would you like to do?
Adding reverse numbers. Solution for the task from ACM Central European Programming Contest, Prague 1998 http://www.spoj.pl/problems/ADDREV/
def addrev(n)
b = 0
n.split(' ').each do |a|
b+= a.to_s.reverse.to_i
end
return b.to_s.reverse.to_i
end
a = true
i = j = 0
out = []
$stdin.each_line do |line|
if(!a) then
if(j != i)
out.push(addrev(line.to_s))
j += 1
else
break
end
else
i = line.to_i
a = false
end
end
out.each do |b|
$stdout << b << "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment