Skip to content

Instantly share code, notes, and snippets.

@pwittchen
Last active December 11, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwittchen/4588162 to your computer and use it in GitHub Desktop.
Save pwittchen/4588162 to your computer and use it in GitHub Desktop.
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