gpt4 book ai didi

java - 扫描仪类输入问题

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:43 25 4
gpt4 key购买 nike

嗨,我正在尝试解决今年谷歌代码堵塞的公平和公正的大量输入。我已经为大问题 1 提供了足够快的工作代码。但是,当我将输入粘贴到控制台中时,它不会读取全部内容。事实上,它只是出于某种原因读取最后的输入。我想粘贴输入并获取输出。扫描仪类是否导致了问题?

代码:

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]);
}
}

现在的问题是,如果我粘贴输入:

5
1 100
2 200
1 500
1 1000000
1 1000000000

这行不通但如果我单独输入每一行,它就会起作用我该怎么做才能粘贴输入?谢谢

最佳答案

尝试这样的事情:

String input ="";
while (reader.hasNextLine()){
input = reader.nextLine();
//parse each line

}

关于java - 扫描仪类输入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16101286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com