我的代码应该输出5个案例,但它只输出4个而且我必须再次按Enter键才能打印第5个输出 代码:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class BeautifulStrings2 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
//File f=new File("input.txt");
Scanner in=new Scanner(System.in);
//BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
int n=in.nextInt();
in.nextLine();
for (int i=1;i<=n;i++){
String s=in.nextLine();
//System.out.println(s);
String chars="";
if (Character.isUpperCase(s.charAt(0))){
chars+=s.charAt(0);
}
else {
chars+=Character.toUpperCase(s.charAt(0));
}
for (int j=0;j<s.length();j++){
boolean flag=true;
for (int k=0;k<chars.length();k++){
if (Character.isLetter(s.charAt(j))){
if (chars.charAt(k)==Character.toUpperCase(s.charAt(j))){
flag=false;
break;
}
}
}
if (flag){
chars+=Character.toUpperCase(s.charAt(j));
}
}
String temp=chars;
chars="";
for (int j=0;j<temp.length();j++){
if (temp.charAt(j)>64&&temp.charAt(j)<91)
chars+=temp.charAt(j);
}
int [] numbers=new int[chars.length()];
Arrays.fill(numbers, 0);
for (int j=0;j<chars.length();j++){
for (int k=0;k<s.length();k++){
if (chars.charAt(j)==Character.toUpperCase(s.charAt(k))){
numbers[j]++;
}
}
}
//System.out.println(chars);
Arrays.sort(numbers);
int factor=26,sum=0;
for (int j=chars.length()-1;j>=0;j--){
sum+=numbers[j]*factor;
factor--;
}
System.out.println("Case #"+i+": "+sum);
}
}
}
预期产出:
Case #1: 152
Case #2: 754
Case #3: 491
Case #4: 729
Case #5: 646
实际输出:
Case #1: 152
Case #2: 754
Case #3: 491
Case #4: 729
当我再次按下输入第五个案例时...如何强制打印而不必更改输入,这是
5
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves