题目描述
Given a string containing only "A"-"Z", we could encode it using the following method:We use 3 characters to represent a sub-string if there are some consecutive repeating characters in one line, which "0" is as the mark, and then the repeat number , and the character itself.输入The first line contains an integer N (1≤N ≤100) which indicates the number of test cases.The next N lines contain N strings. Each string consists of only "A"-"Z" and the length is lessthan 80.输出For each test case, output the encoded string in a line.样例输入2ABBCBBCCC样例输出A02BC02B03C
关键: The first line contains an integer N (1≤N ≤100) which indicates the number of test cases. The next N lines contain N strings.
#include// 处理每一行数据void solve(char* str){ char ch; int count; while(*str){ //每个字符至少存在一个的 count = 1; //遍历与当前第1个字符相同的字符并计数 for(ch=*str++;*str&&*str==ch;str++){ count++; } if(count==1){ //--------仅一次,输出原字符 printf("%c",ch); }else{ //---------------最多3个,不足用零补足 printf("%02d%c",count,ch); } } printf("\n");}int main(void){ //1<=N<=100,字符串长度<80 char astr[100][80]; int N,i; scanf("%d\n",&N); //按照题目要求,先读入所有待处理的数据 //不能读入一个就处理一个 for(i=0;i
女孩不哭 @ 2013-05-08 22:24:30 @ http://www.cnblogs.com/nbsofer