标签:style blog http color os io for art
#include<stdio.h> #include<string.h> int main() { int i = 0, j, k, r, table[200] = {0}, table2[200] = {0}; char st[100]; gets(st); k = strlen(st); for(i = 0;i < k; i++){ j = st[i]; table[j] = table2[j] += 1; } for(i = 0;i < k; i++){ j = st[i]; if(table2[j]){ for(r = 0;r < table2[j]; r++) printf("%c",st[i]); table2[j] = 0; } } puts(""); for(i = 0;i < k; i++){ j = st[i]; if(table[j]){ printf("%c%d",st[i],table[j]); table[j] = 0; } } return 0; }
输入一段字符串,把相同的字符按出现顺序,归在一起,并压缩
比如:
输入 SamSameCome
输出:
SSaammmeeCo
S2a2m3e2C1o1
输入 ComeTomeTCoe
输出:
CCooommeeeTT
C2o3m2e3T2
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/SDUTYST/p/3871542.html