hdu 1020 Encoding
来源:互联网 发布:开淘宝网店一件代发 编辑:程序博客网 时间:2024/05/29 11:08
Description
Given a string containing only 'A' - 'Z',we could encode it using the following method:
1. Each sub-string containing k samecharacters should be encoded to "kX" where "X" is the onlycharacter 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 linescontain N strings. Each string consists of only 'A' - 'Z' and the length isless than 10000.
Output
For each test case, output the encodedstring in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
题意:输入字符串,输出格式为“数字-字符”,数字为该字符出现的次数。
若输入ABBAB,输出的应该是A2BAB,而不是2A3B
#include<stdio.h>#include<string.h>int main(){ int i,n,count,k; char a[10001]; while(~scanf("%d",&n)) { scanf("%s",a); k=strlen(a);count=1; for(i=0;i<k;i++) { if(a[i]==a[i+1]) count++; else { if(count==1) printf("%c",a[i]); else printf("%d%c",count,a[i]); count=1; } } 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
- 【安卓基础一】安卓架构、Dalvik VM、apk与.dex
- DataGrid- formatter:formatOper方法不可用
- 我的Android进阶之旅------>Android SDK支持的配置标识符(有用的参考文件)
- IOS SEL (@selector) 原理及使用总结(二)
- 个人对opencv在不同使用环境下要编译的理解
- hdu 1020 Encoding
- 深刻理解Linux进程间通信(IPC)
- pat 1041. Be Unique (20)
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- Java中关于json的转义字符解析
- 2.4 Python是如何进行类型转换的?
- ios 线程同步
- 股票学习24
- 2015SAAS服务图表