hdu acm 2564 词组缩写 用java的 提交六次都wa 我整不出其他的漏洞了 求帮助啊
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(Stringargs[]){Scannersca...
import java.util.Scanner;
public class Main {
public static void main( String args[] ){
Scanner scan = new Scanner ( System.in );
int t;
String str;
char[] b = new char[200];
t = scan.nextInt();
str = scan.nextLine();
while(t-- != 0){
int i = 0, j = 0, k = 0;
String s;
s = scan.nextLine();
for(i = 0; i < 200; i++)
b[i] = ' ';
for(i = 0; i < s.length(); i++){
if(i==0)
{
if( s.charAt(i) ==' ' && s.charAt(i+1) !=' ')
b[k++] = s.charAt(i + 1);
else if(s.charAt(i) != ' ')
b[k++] = s.charAt(i);
}
else if(i == s.length() - 1){
if(s.charAt(i) != ' ' && s.charAt(i-1) == ' ')
b[k++] = s.charAt(i);
else
continue;
}
else
{
if(s.charAt(i)==' ' && s.charAt(i+1) > 0)
b[k++]=s.charAt(i+1);
}
}
for(i=0;i<k;i++)
{
if(b[i] >= 'a' && b[i] <= 'z')
b[i] = (char) (b[i] - 32);
}
for(i=0;i<k;i++)
if(b[i]!=' ')
System.out.print(b[i]);
System.out.println("");
}
}
} 展开
public class Main {
public static void main( String args[] ){
Scanner scan = new Scanner ( System.in );
int t;
String str;
char[] b = new char[200];
t = scan.nextInt();
str = scan.nextLine();
while(t-- != 0){
int i = 0, j = 0, k = 0;
String s;
s = scan.nextLine();
for(i = 0; i < 200; i++)
b[i] = ' ';
for(i = 0; i < s.length(); i++){
if(i==0)
{
if( s.charAt(i) ==' ' && s.charAt(i+1) !=' ')
b[k++] = s.charAt(i + 1);
else if(s.charAt(i) != ' ')
b[k++] = s.charAt(i);
}
else if(i == s.length() - 1){
if(s.charAt(i) != ' ' && s.charAt(i-1) == ' ')
b[k++] = s.charAt(i);
else
continue;
}
else
{
if(s.charAt(i)==' ' && s.charAt(i+1) > 0)
b[k++]=s.charAt(i+1);
}
}
for(i=0;i<k;i++)
{
if(b[i] >= 'a' && b[i] <= 'z')
b[i] = (char) (b[i] - 32);
}
for(i=0;i<k;i++)
if(b[i]!=' ')
System.out.print(b[i]);
System.out.println("");
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询