HDU 1020.Encoding-字符压缩
2024-08-29 10:56:58
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 55351 Accepted Submission(s): 24697
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.
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
ABC
ABBCCC
Sample Output
ABC
A2B3C
A2B3C
Author
ZHANG Zheng
代码:
#include<stdio.h>
#include<string.h>
int main(){
char str[];
int n,i,cnt;
while(~scanf("%d",&n)){
while(n--){
scanf("%s",&str);
for(i=;str[i]!='\0';i++){
cnt=;
while(str[i]==str[i+]){
cnt++;i++;
}
if(cnt==) printf("%c",str[i]);
else printf("%d%c",cnt,str[i]);
}
printf("\n");
}
}
return ;
}
最新文章
- PHP 如何获取当前的域名
- Atitit RSA非对称加密原理与解决方案
- uploadfile上传文件时ie浏览器无法弹出窗口
- head first c&;lt;11&;gt;初探网络编程上
- [译]JavaScript 错误和处理
- javascript 的点击复制事件
- python文本文件,生成指定的文件格式
- MySQL索引的使用方式
- oracle查询用户权限及角色(摘)
- [Flask]学习杂记--模板
- 记账本-NABCD分析
- 【工具】idea工具 java代码 gbk转utf8
- CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-6CM安装前环境检查
- VS Code 编辑器
- MySQL基础知识——范式与事务
- android 退出程序解决内存释放so的问题
- express4.x Request对象获得参数方法小谈【原创】
- python列表解析进阶
- Session和Cookie详解(1)
- bzoj 4004 [JLOI2015]装备购买 拟阵+线性基