HDU 1020 Encoding 字符串操作
来源:互联网 发布:蜂群算法matlab 编辑:程序博客网 时间:2024/04/28 17:55
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43902 Accepted Submission(s): 19397
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
Author
ZHANG Zheng
Recommend
JGShining | We have carefully selected several similar problems for you: 1062 1003 1039 1073 1108
给你一个字符串然后让你改变一下输出格式,切记不能排序啊,排序就是错的。
ac代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;bool cmp(char x,char y){return x < y ? true : false;}int main(){int t,i,j,n,num,cnt[10005];char a[10005],b[10005],tmp;int place;while(~scanf("%d",&t)){while(t--){scanf("%s",a);//printf("%s\n",a);n=strlen(a);//sort(a,a+n,cmp);memset(cnt,0,sizeof(cnt));tmp=a[0];num=1;place=0;for(i=1;i<n;i++){if(a[i]==tmp)num++;else{b[place]=tmp;cnt[place]=num;place++;num=1;tmp=a[i];}}b[place]=tmp;cnt[place]=num;place++;for(i=0;i<place;i++){if(cnt[i]>1)printf("%d",cnt[i]);printf("%c",b[i]);}printf("\n");}}return 0;}
万里长城永不倒,再来一题好不好
1 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 1020 Encoding 典型的字符串的压缩
- hdu 1020 Encoding(模拟)
- HDU 1020 Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- HDU 1020 Encoding
- Hdu 1020 - Encoding
- 最短路径--九度1008.[Dijkstra]
- 如何查看Windows下端口占用情况
- 简易管理器(驱动方式)
- DFD的绘制步骤
- Hadoop学习笔记—8.Combiner与自定义Combiner
- HDU 1020 Encoding 字符串操作
- Missing artifact com.sun:tools:jar:1.x.x解决办法
- 滑动窗口的最大值
- Oracle高级查询之OVER (PARTITION BY ..)
- 文章标题
- Java Web(三) 会话机制,Cookie和Session详解
- PHP后端利用七牛快速搭建个人网站图床
- Hibernate JPA 悲观锁,乐观锁
- (动态规划)最长回文子序列、回文子序列个数