Encoding
来源:互联网 发布:数据库范式的算法例题 编辑:程序博客网 时间:2024/05/11 03:16
Description
Given a string containing only 'A' - 'Z', we could encode it using the following method:
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
Input
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 less than 10000.
Output
For each test case, output the encoded string in a line.
Sample Input
2ABCABBCCC
Sample Output
ABCA2B3C
之前比赛时做过这个题,但是因为对这种题不熟练,所以没有做,先在尝试做了这道题,感觉只是边尝试边做的,虽然一次做对了,但是感觉明显自己的代码很不成熟!
#include<stdio.h>#include<string.h>int main(){ int i,j,m,n,s; char str[11000]; scanf("%d\n",&m); while(m--) { gets(str); n=strlen(str); int p=0; for(i=0;i<n;) { s=0; for(j=i;j<n;j++) { if(str[i]==str[j]) s++; else break; } if(s==1) printf("%c",str[i]); else printf("%d%c",s,str[i]); i=i+s; } printf("\n"); } return 0;}
0 0
- Encoding
- Encoding
- encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- Encoding
- CSS中RGBA的兼容方法以及透明度计算方法
- 一份招PHP高级工程师的面试题
- 算法导论学习 之 顺序统计量的O(n)算法
- 编译GDB(主要针对LINUX平台)
- PIE使用阴影后的背景透明方法
- Encoding
- hdoj-1106
- HDU 2116 Has the sum exceeded (大数)
- MySQL字段自增自减的SQL语句
- 好累啊
- 找出集合S最接近中位数的k(k≤n)个数
- Codeforces 383A Milking cows(贪心)
- 英文排版(typography)
- Fibonacci Again