import java.util.Scanner;
public class Main{
public static void main(String[] strs){
Scanner sca = new Scanner(System.in);
String str=sca.nextLine();
int pointer=0;
if(str==null||str.length()==0){
System.out.println("");
return;
}
StringBuffer sb = new StringBuffer();
int count=0;
for(;pointer<str.length();pointer++){
count=1;
for(int i=pointer+1;i<str.length();i++){
if(str.charAt(i)==str.charAt(pointer)){
count++;
continue;
}else{
break;
}
}
if(count==1){
sb.append(str.charAt(pointer));
}else{
sb.append(count);
sb.append(str.charAt(pointer));
pointer=pointer+count-1;
}
}
System.out.println(sb.toString());
}
}
字符串压缩
最新推荐文章于 2024-09-11 23:34:55 发布