ZOJ 2478 Encoding
Encoding
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 100.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
string s;
cin >> n;
while(n--){
cin >> s;
int len = s.length();
int num = ;
if(len == ){
cout << s << endl;
continue;
}
for(int i = ; i < len - ; i++){
if(s[i] == s[i + ]){
num++;
} else {
if(num == )
cout << s[i];
else
cout << num << s[i] ;
num = ;
}
}
if(s[len - ] == s[len - ])
cout << num << s[len - ];
else
cout << s[len - ];
cout << endl;
}
// system("pause");
return ;
}
ZOJ 2478 Encoding的更多相关文章
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
- ZOJ 3430 Detect the Virus
传送门: Detect the Virus ...
- ZOJ 4114 Detect the Virus(AC自动机)
Detect the Virus Time Limit: 2 Seconds Memory Limit: 65536 KB One day, Nobita found that his co ...
- ZOJ - 3430 Detect the Virus —— AC自动机、解码
题目链接:https://vjudge.net/problem/ZOJ-3430 Detect the Virus Time Limit: 2 Seconds Memory Limit: 6 ...
- Detect the Virus ZOJ - 3430 AC自动机
One day, Nobita found that his computer is extremely slow. After several hours' work, he finally fou ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- javac -encoding utf8 in linux
由于另外负责编码的同事用的是utf-8,我用的默认的编码格式gbk,在提交代码时,为了迁就他,我打算把格式用工具转成utf-8. 转化成果后,然后在make一下,发现javac -encoding u ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 创建Odoo8数据库时的“new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)“问题
Odoo8创建数据库时,显示如下错误信息: DataError: new encoding (UTF8) is incompatible with the encoding of the templa ...
随机推荐
- CentOS 6.9 --Squid代理服务器
主机名 IP地址 网关 DNS 服务类型 Master eth0:192.168.17.130(VMnet4) eth1:192.168.30.130(NAT) 192.168.30.2 ...
- Jquery 中使用String.Format
第一种方法: String.format = function() { if (arguments.length == 0) return null; var str = arguments[0]; ...
- wp跳转到评价界面代码
wp跳转到评价界面代码(仅适用于wp8.0) MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask(); ma ...
- 你有学习者综合征吗?Web 开发是重灾区
[导读]:学习者综合征的主要表现:学而不用,不停学习,却没有真正实际应用知识来做东西.如果过去的一年里,学习的语言或框架超过三个,那可能已经感染学习者综合征了.Web 开发是重灾区咯. 你有学习者综合 ...
- iPhone4 offical AD
iPhone4 is so much more than just a new products.I mean this would have a lot of impact on the way i ...
- python中的seteuid
seteuid(...) seteuid(uid) Set the current process's effective user id.
- sql查询作业执行时间
SELECT j.name AS Job_Name , h.step_id AS S ...
- 51nod 1067 Bash游戏 V2
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人获胜.假设A B都非常聪 ...
- DROP SEQUENCE - 删除一个序列
SYNOPSIS DROP SEQUENCE name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP SEQUENCE 从数据库中删除序列号生成 ...
- Modal 高度 在里面css里写高 | iview
.modalCss { height: 330px; overflow: auto; padding-right: 10px; }