Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:59:38+00:00 2026-05-16T17:59:38+00:00

I did go through the other threads on this SPOJ problem, ADDREV ( Adding

  • 0

I did go through the other threads on this SPOJ problem, ADDREV (Adding Reversed Numbers), 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.

Python:

    def find_rev(a):
        d=0

        while(a>=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

With Python, I get a runtime error.

With C, I get a wrong answer.

    #include<stdio.h>
    long rev(long);
    int main()
    {
        long int n;
        long int n1;
        long int n2;
        long int i=0;
        scanf("%ld",&n);
        //printf("%d",n);
        for (i=0;i<n;i++)
        {
            //printf("\n%d",i);
            //printf("\nenter the two numbers");
            scanf("%ld%ld",&n1,&n2);

            n = rev(rev(n1)+rev(n2));
            printf("%ld\n",n);
        }
        return 0;
    }

    long rev(long a)
    {
        long d=0;
        while(a>=1)
        {
            d = d*10+a%10;
            a = a/10;
        }
        return d;
    }

With Java, I get a compilation error.

    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<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>=1)
            {
                d=d*10+a%10;
                a=a/10;
            }
            return d;

            }
        }
    }

Of course, those errors are reported by the SPOJ Judge. The programs work fine on my system. Test cases I use are:

    2

    999999999 11

    999 11

Answer

    101
    101

Also

    3

    34 54

    123 091

    00034 00054

Update: Guys, I got the answer in C. Thank you for all the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:59:38+00:00Added an answer on May 16, 2026 at 5:59 pm

    Before you start using any service, it’s generally a good thing to read its FAQ. It explains how exactly the program should receive data.

    In particular, please notice that printing enter a number and other junk to the console will always lead to a wrong answer. Because a correct program would output something like

    34
    1998
    1
    

    and yours

    enter a number
    enter two numbers
    34
    enter two numbers
    1998
    enter two numbers
    1
    

    I can’t tell why Java fails to compile, though. You probably should find some information on how to submit in Java with the reference solution.

    Also, the problem definition gives no limit for input numbers, so they can possibly be too big for standard integer types in Java and C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i already gone through other web game cheating question on this forum but i
I went through similar questions here but did not find an answer to the
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
I've looked through all other topics on this issue, and I can't still solve
I am trying to compile a C program through a javacode. I did it
I'm trying to make a click at desktop through code, so I did that:
Did you ever have the following situation: you need to store information, but a
Did about 30 minutes worth of searching, found lots of relevant info, but none
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
First off, I know I can copy "this" on instantiation, but that doesn't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.