初学者,浙大ACM网站上1151题Word Reversal,小弟我的程序答案对的,但老显示PE,不知道格式错哪了
菜鸟求助,浙大ACM网站上1151题Word Reversal,我的程序答案对的,但老显示PE,不知道格式哪里错了
题目如下:
For each list of words, output a line with each word reversed without changing the order of the words.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
You will be given a number of test cases. The first line contains a positive integer indicating the number of cases to follow. Each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.
Output
For each test case, print the output on one line.
Sample Input
1
3
I am happy today
To be or not to be
I want to win the practice contest
Sample Output
I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
代码如下:
import java.util.Scanner;
public class Test1151{
public void sort(char a[]){
char temp;
for(int i=0;i<(a.length-1);i++){
for(int j=0;j<(a.length-i-1);j++){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
public static void main(String args[]){
Scanner scan=new Scanner(System.in);
int a,b,c,d;
int k1;
int k2;
k1=scan.nextInt();
String s;
String s2[];
String s1;
for(a=0;a<k1;a++){
System.out.println();
k2=scan.nextInt();
scan.nextLine();
for(b=0;b<k2;b++){
s=scan.nextLine();
s2=s.split(" ");
for(c=0;c<s2.length;c++){
int e=0;
s1=s2[c];
char k3[]=new char[s1.length()];
for(d=0;d<s1.length();d++){
k3[d]=s1.charAt(d);
}
Test1151 b1=new Test1151();
b1.sort(k3);
for(int i=0;i<k3.length;i++){
System.out.print(k3[i]);
}
e++;
if(e<s2.length){
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
------解决思路----------------------
不好意思,错了,然后读入的nextLine()其实是个空字符串
题目如下:
For each list of words, output a line with each word reversed without changing the order of the words.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
You will be given a number of test cases. The first line contains a positive integer indicating the number of cases to follow. Each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.
Output
For each test case, print the output on one line.
Sample Input
1
3
I am happy today
To be or not to be
I want to win the practice contest
Sample Output
I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
代码如下:
import java.util.Scanner;
public class Test1151{
public void sort(char a[]){
char temp;
for(int i=0;i<(a.length-1);i++){
for(int j=0;j<(a.length-i-1);j++){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
public static void main(String args[]){
Scanner scan=new Scanner(System.in);
int a,b,c,d;
int k1;
int k2;
k1=scan.nextInt();
String s;
String s2[];
String s1;
for(a=0;a<k1;a++){
System.out.println();
k2=scan.nextInt();
scan.nextLine();
for(b=0;b<k2;b++){
s=scan.nextLine();
s2=s.split(" ");
for(c=0;c<s2.length;c++){
int e=0;
s1=s2[c];
char k3[]=new char[s1.length()];
for(d=0;d<s1.length();d++){
k3[d]=s1.charAt(d);
}
Test1151 b1=new Test1151();
b1.sort(k3);
for(int i=0;i<k3.length;i++){
System.out.print(k3[i]);
}
e++;
if(e<s2.length){
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
------解决思路----------------------
不好意思,错了,然后读入的nextLine()其实是个空字符串