Hi I am trying to solve large input of fair and square of google code jam of this year. I have got a good enough fast working code for large problem 1. However when I paste input it in console does not read all of it. Infact it just reads the last input for some reason. I want to paste input and get output. Is the scanner class causing the problem?
Code :
import java.util.Scanner;
class rishab {
public static int check() {
Scanner reader = new Scanner(System.in);
double A=reader.nextLong();
long B=reader.nextLong();
int count = 0;
long i;
if((long)Math.sqrt(A)==Math.sqrt(A))
i= (long)Math.sqrt(A);
else
i=(long)Math.sqrt(A)+1;
for(;i<=Math.sqrt(B);i++) {
if(i==reverse(i) && Math.pow(i,2)==reverse((long)Math.pow(i,2)))
count++;
}
return(count);
}
public static long reverse(long number) {
long result = 0;
while (number != 0) {
long remainder = number % 10;
result = result * 10 + remainder;
number /= 10;
}
return result;
}
public static void main(String str[]) {
int[] a= new int[10000];
Scanner reader = new Scanner(System.in);
int T= reader.nextInt();
for(int i=0;i<T;i++)
a[i]=check();
for(int i=0;i<T;i++)
System.out.println("Case #"+(i+1)+": "+a[i]);
}
}
Now the problem is if I for example PASTE input :
5
1 100
2 200
1 500
1 1000000
1 1000000000
It wont work but if i type each line separately it will work What do i do so that I can paste the input? Thanks