Encoding
2015-06-25 21:56
183 查看
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32145 Accepted Submission(s): 14263
Problem Description
Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method:
Each sub-string containing k same characters should be encoded to “kX” where “X” is the only character in this sub-string.
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
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
看错了题,错了好几次
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32145 Accepted Submission(s): 14263
Problem Description
Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method:
Each sub-string containing k same characters should be encoded to “kX” where “X” is the only character in this sub-string.
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
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
看错了题,错了好几次
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; struct AZ { char s[11100]; int num; int len; void Input() { scanf("%s",s); } void CAL() { len=strlen(s); for(int i=0; i<len; i++) { num=1; while(s[i]==s[i+1]) { i++; num++; } if(num!=1) { cout<<num<<s[i]; } else { cout<<s[i]; } } cout<<endl; } } a; int main() { int n; scanf("%d",&n); while(n--) { a.Input(); a.CAL(); } return 0; }
相关文章推荐
- java线程基础复习
- 安装时提示 INSTALL_PARSE_FAILED_MANIFEST_MALFORMED 解决办法
- Encoding 分类: HDU 2015-06-25 21:56 9人阅读 评论(0) 收藏
- JAVAC不是内部或外部命令
- 局域网找不到其它电脑
- Activity嵌套多个Fragment实现横竖屏切换
- 浅谈移动前端的最佳实践
- 手斧Linux – 从LFS到Funtoo (45)
- 运行hibernate时报错Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntit
- 【无中生有】---11---服务器集群部署
- HDU 2686 Matrix(最大费用流)
- 8.Tomcat 如何启动停止?
- 数据绑定控件之Repeater
- HDOJ 1009
- 玩转Docker镜像
- html5中canvas中绘制渐变和绘制文字顺序问题
- 实现顺序栈
- 手斧Linux – 从LFS到Funtoo (44)
- 黑马程序员——Java基础--多态
- 添加ASM磁盘报错ORA-02097和ORA-15014