为什么一直显示说只能测试一组数据,在电脑上可以测试多组数据

//代码如下,在电脑上可以测试多组数据,但是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;
}
}
全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
zzzilik:四个月实习做了3个项目不觉得很假吗,真没必要写这么多吧我感觉挑点核心的重点写一下我感觉会好点
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务