62,628
社区成员
发帖
与我相关
我的任务
分享import java.util.*;
public class PAT {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int n = sc.nextInt();
for(int i = 0; i < n-1; i++) {
str = method(str);
}
System.out.println(str);
}
public static String method(String input) {
StringBuilder str = new StringBuilder();
int i = 0, number = 1;
char b, a = input.charAt(i);
i++;
while(i < input.length()) {
b = input.charAt(i);
if(b == a) {
number++; i++;
}else {
str.append(a);
str.append(number);
a = input.charAt(i);
number = 1;
i++;
}
}
str.append(a); str.append(number);
return str.toString();
}
}