Sorry, this entry is only available in Polski.
-
Recent Posts
Recent Comments
Archives
Categories
Meta
Sorry, this entry is only available in Polski.
Sorry, this entry is only available in Polski.
In this post, I will show my proposal of adding reversed numbers algorithm.
Problem is described on the website: http://www.spoj.pl/problems/ADDREV/ and appeared during the ACM Central European Programming Contest, Prague 1998.
The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.
For each case, print exactly one line containing only one integer – the reversed sum of two reversed numbers. Omit any leading zeros in the output.
3
24 1
4358 754
305 794
34
1998
1
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
i = line.to_i
a = false
else
if(j != i)
out.push(addrev(line.to_s))
j += 1
else
break
end
end
end
out.each do |b|
$stdout << b << "\n"
end
Sorry, this entry is only available in Polski.
I was planning to create a blog some time ago, but I didn’t have enough time and motivation. This time, I’ve decided to finally create some kind of my e-notebook. I’m going to put here my ideas, experiments and inspirations connected with IT. I’m not sure yet about concrete topics of the articles, but I have some ideas about that. I’ll see how it works in practice and if anybody is interested in content presented by me. I assume, that when I teach somebody, I also teach myself. That’s why I will try to present here some solutions to different problems and description of interesting stuff. Maybe some posts will touch also non-technical topics. I’ll see. Blog consists of two language versions: Polish and English. I am not English native speaker, so I apologize for all my mistakes in advance. If you find some mistakes in my posts, please notify me about that in comments or send me an e-mail.
Technical stuff
During creating this blog, I used Pareto Principle and deployed free open-source software WordPress. I’ve installed plugin for responsive web design dedicated for current template, so you can browse this blog on various devices (netbooks, mobile phones with Android OS, iOS, tablets), plugin for multi-language website, Latex and syntax highlighter. Of course, I could spend a lot of time on writing my own blog software and probably it would be faster, but achieving such a great functionality like in WordPress would take me half of a year or even longer and final user wouldn’t see the big difference. Due to the fact, that content is going to be main value of this blog, that choice is justifiable.