一、题目链接
http://noi.openjudge.cn/ch0107/32/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Scanner;
public class Main {
public String compressedCode(String text) {
StringBuilder ans = new StringBuilder();
char[] chars = text.toUpperCase().toCharArray();
int n = chars.length;
int count;
int next;
for (int i = 0; i < n; i = i + count) {
count = 1;
next = i + 1;
while (next < n && chars[next] == chars[i]) {
count++;
next++;
}
ans.append("(").append(chars[i]).append(",").append(count).append(")");
}
return ans.toString();
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
String text = input.next();
System.out.print(test.compressedCode(text));
}
}