为什么一直显示说只能测试一组数据,在电脑上可以测试多组数据
//代码如下,在电脑上可以测试多组数据,但是OJ一直不行,不知道哪里出了错,
//请也碰到过这种问题的大神不吝赐教,感激不尽。
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {//while处理多个case
try{
String line = in.nextInt();
BigInteger h = new BigInteger(line);
int x = sqrt(line);
for (int i=x;i>0;i--){
BigInteger temp = new BigInteger(i+"");
BigInteger y = temp.multiply(temp).add(temp);
if (y.compareTo(h)!=1){
System.out.println(temp);
break;
}
}
}catch(Exception e){
System.out.println(in.nextLine());
continue;
}
}
}
public static int sqrt(String num){
String data[];
int j;
if (num.length()%2==0){
data = new String[num.length()/2];
j = num.length()/2-1;
}
else{
data = new String[num.length()/2+1];
j = num.length()/2;
}
int i = num.length();
while(i>0){
if (i>1)
data[j] = num.substring(i-2,i);
else
data[j] = num.substring(0,1);
i-=2;
j--;
}
int res = 0;
int d = 0;
int z = 0;
for (i=0;i<data.length;i++){
int y = Integer.parseInt(data[i]) + d*100;
if (i==0){
z = (int)Math.sqrt(y);
res = z%10;
d = y-z*z;
}
else{
int s = 1;
int k;
for (k=0;k<=9;k++){
s = res*20+k;
if (s*k>y)
break;
}
if (k==10)
k--;
z = s-1;
res = res*10 + (k-1);
d = y - z*(k-1);
}
}
return res;
}
}

