Note that there are some explanatory texts on larger screens.

plurals
  1. POSPOJ ADDREV Problem
    primarykey
    data
    text
    <p>I did go through the other threads on this <a href="http://en.wikipedia.org/wiki/SPOJ" rel="nofollow noreferrer">SPOJ</a> problem, <a href="https://www.spoj.pl/problems/ADDREV/" rel="nofollow noreferrer">ADDREV</a> (<em>Adding Reversed Numbers</em>), but sadly, I was not able to get an answer by any of the three programs that I have written (in C, Python and Java). I am attaching the code snippets of all three.</p> <p>Python:</p> <pre><code> def find_rev(a): d=0 while(a&gt;=1): d=d*10+a%10 a=a/10 return d n=input('enter a number') for i in range(int(n)): num1=input('enter the first number') num2=input('enter the second number') num=0 num1=find_rev(int(num1)) num2=find_rev(int(num2)) num=num1+num2 num=find_rev(num) print num </code></pre> <p>With Python, I get a runtime error.</p> <p>With C, I get a wrong answer.</p> <pre><code> #include&lt;stdio.h&gt; long rev(long); int main() { long int n; long int n1; long int n2; long int i=0; scanf("%ld",&amp;n); //printf("%d",n); for (i=0;i&lt;n;i++) { //printf("\n%d",i); //printf("\nenter the two numbers"); scanf("%ld%ld",&amp;n1,&amp;n2); n = rev(rev(n1)+rev(n2)); printf("%ld\n",n); } return 0; } long rev(long a) { long d=0; while(a&gt;=1) { d = d*10+a%10; a = a/10; } return d; } </code></pre> <p>With Java, I get a compilation error.</p> <pre><code> import java.util.*; //import java.io.*; public class spoj_prob { public static void main(String args[]) { long n=0; System.out.println("enter a number \n"); Scanner in=new Scanner(System.in); n=in.nextLong(); long n1=0; long n2=0; long sum=0; for (int i=0; i&lt;n; i++) { System.out.println("enter two numbers \n "); n1=in.nextLong(); n2=in.nextLong(); n1=rev(n1); n2=rev(n2); System.out.println(n1); System.out.println(n2); sum=rev(n1+n2); System.out.println(sum); } } static long rev(long a) { long d=0; while (a&gt;=1) { d=d*10+a%10; a=a/10; } return d; } } } </code></pre> <p>Of course, those errors are reported by the SPOJ Judge. The programs work fine on my system. Test cases I use are:</p> <pre><code> 2 999999999 11 999 11 </code></pre> <p>Answer</p> <pre><code> 101 101 </code></pre> <p>Also</p> <pre><code> 3 34 54 123 091 00034 00054 </code></pre> <p><strong>Update</strong>: <strong>Guys, I got the answer in C</strong>. Thank you for all the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload