HDU 1020 Encoding
来源:互联网 发布:怎样建淘宝团购微信群 编辑:程序博客网 时间:2024/06/05 21:11
Encoding
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
分析
简单的暴力,直接遍历一边输出结果即可,注意cnt==1时的特殊输出。
AC代码如下:
#include <cstdio>#include <cstring>using namespace std;int main(){ int t,i,cnt; char ch[10005]; scanf("%d",&t); while(t--) { scanf("%s",ch); for(i = 0; ch[i]!='\0';) { cnt = 1; while(ch[i] == ch[i+1]) //计算重复次数 { cnt++; i++; } if(cnt == 1) printf("%c",ch[i]); //等于1的时候特殊处理 else printf("%d%c",cnt,ch[i]); i++; } printf("\n"); } return 0;}
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
- Entity Framework中数据缓存的问题
- tar.xz文件如何解压
- redis中各种数据类型对应的jedis操作命令
- Dissect Bluedroid From A2DP Part I: Use Case
- UML 基础: 序列图
- HDU 1020 Encoding
- XMPP系列(一):OpenFire环境搭建
- Linux入门
- qrencode二维码生成在linux下的编译
- 数学模型中包括多个变量的例子:称硬币
- Dissect Bluedroid From A2DP: Part II: Init Bluetooth Adapter
- 分析Maya摄像机导入Nuke的方案
- Python源码剖析笔记4-内建数据类型
- 先安装了fedora22 后安装windows8.1双系统的引导