私はUVA(10324)から質問をしていましたが、常に時間制限を取得し続けています。私はかなりコードが正しいと確信していますが、まだコードは無限ループに入ります。私はこの質問を6回試みましたが、それを渡すことはできません。UVA 10324ゼロとワン
誰かが間違っている可能性がどのようにいくつかの光を当てることができます:
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ii=1;
boolean flag = false;
while(sc.hasNextLine()){
String str = sc.nextLine();
if(str.trim().isEmpty())
break;
int TC = sc.nextInt();
System.out.println("Case " +ii+++":");
while(TC-->0){
flag = false;
int a = sc.nextInt();
int b = sc.nextInt();
int c=0;
if(a>b){
c=a;
a=b;
b=c;
}
c = str.charAt(a)-'0';
for(int i=a+1;i<=b;i++){
if(str.charAt(i)-'0' != c){
flag = true;
break;
}
}
System.out.println(flag?"No":"Yes");
}
try{
sc.nextLine();
}
catch(Exception ex){
break;
}
}
}
}
'-'0''は不要です。 –
cはaのインデックス付き整数です。 'Integer.parseInt()'または-'0 'は重要です – BeardAspirant