Reputation: 33
I have used the following code for the question but it keeps giving me NZEC error when I submit it on SPOJ. My code runs perfectly on Eclipse or through cmd.
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
int line,num,numb,rev = 0,r,i,flag;
ArrayList <Integer> nums=new ArrayList <Integer>();
Scanner b=new Scanner(System.in);
Scanner a=new Scanner(System.in);
line=b.nextInt();
for(i=0;i<line;i++)
{flag=0;
num=a.nextInt();
num=num+1;
numb=num;
do {
while(numb>0)
{r=numb%10;
rev=(rev*10)+r;
numb=numb/10;
}
if (rev==num)
{nums.add(num);
rev=0;
flag=1;
break;
}
else
{num=num+1;
numb=num;
rev=0;}
}while(flag==0);
}
for (int newnum : nums)
{System.out.println(newnum);}
}
}
Upvotes: 1
Views: 181
Reputation: 11032
the mistake that you are doing is that you are storing num
in an integer datatype
..the constraint says that
K of not more than 1000000 digits(it is
digits
and not up to thatnumber
)
It is impossible for an integer
to store such a huge number
..so you have to use string
to solve this particular problem..try this input in your eclipse
454646546546546546546546464646464646
you will realize where you are wrong
Upvotes: 1