Last active
December 11, 2015 10:38
-
-
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/
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
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