![]() |
#2
疯狂的小a2018-03-22 09:53
![]() import java.util.Scanner; 已经可以不报错了,但是会有java.lang.ArrayIndexOutOfBoundsExceptionpublic class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String s = in.next(); char type = s.charAt(0); String[] str = new String[100]; if (type == 'C') { int len = str.length; int cnt = 1; for (int i = 0; i < len; i++) { if (str[i] == str[i + 1]) { cnt++; } else { if (cnt > 1) { System.out.printf("%d", cnt); } System.out.printf("%c", str[i]); cnt = 1; } } } else { int len = str.length; int cnt = 0; for (int i = 0; i < len; i++) { if (str[i].toCharArray()[0] <= '9' && str[i].toCharArray()[0] >= '0') { cnt *= 10; cnt += str[i].toCharArray()[0] - '0'; } else { if (cnt == 0) { System.out.printf("%c", str[i]); } else for (int j = 0; j < cnt; j++) { System.out.printf("%c", str[i]); } cnt = 0; } } } } in.close(); } } |

import java.util.Scanner;
public class text {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String s = in.next();
char type = s.charAt(0);
String[] str=new String[100];
if(type == 'C'){
int len = str.length;
int cnt = 1;
for(int i = 0;i < len;i++){
if(str[i] == str[i+1]){
cnt++;
}else{
if(cnt>1){
System.out.printf("%d",cnt);
}
System.out.printf("%c",str[i]);
cnt = 1;
}
}
}else{
int len = str.length;
int cnt = 0;
for(int i = 0;i < len;i++){
if(str[i]<='9'&&str[i]>='0'){
cnt*=10;
cnt+=str[i]-'0';
}else{
if(cnt == 0){
System.out.printf("%c",str[i]);
}else
for(int j = 0;j < cnt;j++){
System.out.printf("%c",str[i]);
}
cnt = 0;
}
}
}
}
in.close();
}
}
只有本站会员才能查看附件,请 登录