HDU 1020 Encoding
来源:互联网 发布:js disabled 失效 编辑:程序博客网 时间:2024/05/16 05:39
Problem 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<iostream>#include<string.h>using namespace std;int main(){char a[10001];int n,lenth,i,sum;cin>>n;while(n>0){cin>>a;lenth=strlen(a);for(i=0;i<lenth;i++){sum=1;while(a[i+1]==a[i])//计数{sum++;i++;}if(sum!=1)//1忽略cout<<sum;cout<<a[i];} cout<<endl;n--;}}
0 0
- hdu 1020 Encoding(模拟)
- HDU 1020 Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- HDU 1020 Encoding
- Hdu 1020 - Encoding
- HDU 1020 Encoding
- hdu 1020 Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- hdu 1020 Encoding
- HDU 1020Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- HDU 1020:Encoding
- hdu 1020 Encoding
- hdu 1020 Encoding
- hdu-1020-Encoding
- IOS学习日志(OC)1.2
- LeeCode_MultiplyStrings
- 简述handler实现异步操作
- 贝叶斯基本公式与理解
- pig mysql 写法比较
- HDU 1020 Encoding
- 超越发展理论
- 全排列递归算法
- SQL简介
- id & instancetype 的区别
- spark大数据应用
- android 日历源码
- JavaScript高级程序设计第15章(使用Canvas)
- 145Binary Tree Postorder Traversal