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 ...
随机推荐
- 转 ORACLE数据库ORA-00392 log 4 of thread 1 is being cleared, operation not allowed错误
现象: 数据库在做to-time recovery, 时候,restore and recover 都是正常的,但是最后一步open resetlogs 报错如下 ORA-00392 原因: 因为是在 ...
- DoTween学习笔记
using DG.Tweening: Tweener 首先dotween在游戏刚开始运行时会默认进行一次初始化 DOTween.Init(); 如果为了有更好的效率,可以手动控制最大同时进行dot ...
- 【转】哪个更快:Java堆还是本地内存
译文出处: shenzhang 原文出处:原文链接 使用Java的一个好处就是你可以不用亲自来管理内存的分配和释放.当你用new关键字来实例化一个对象时,它所需的内存会自动的在Java堆中分配.堆 ...
- let块级引起的闭包思考
因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...
- iOS 利用UIWebView与JavaScript交互的最简单办法
这里说的是针对iOS的!并且方法很简单!!并且验证可行的!!! 1, UIWebView调用 JavaScript 的函数: NSString* strValue = [webView stringB ...
- SAP成都研究院安德鲁:自己动手开发一个Chrome Extension
各位好,我叫何金鑫(He Andrew), 团队同事亲切地称呼在下为安德鲁.如果你在附近找到wifi热点名为 「安德鲁森面包房5g」,可能是我就在附近,我们可以去喝杯咖啡,聊聊最近有趣的东西. 鄙人现 ...
- 11gR2集群件任务角色分离(Job Role Separation)简介
从11gR2版本开始,Oracle推荐使用不同的操作系统用户安装GI和数据库软件,例如:使用grid用户安装GI,使用Oracle用户安装数据库软件.当然,用户还是可以使用Oracle用户安装G ...
- Graveyard LA3708
白书第一章例题4 思维. 先固定一点不动,假设最后一共N个点,那么编号为0,1,...N-1, 0不动,原来的n个点分别占据i/n*N的位置(记为pos),移动到pos四舍五入的位置即可. 证明一:有 ...
- iview upload 上传图片 不传服务器 转 base64
开始的时候 找不到this了,后来想起来要用 ES6的箭头函数 就有this了 reader.onload = e => { // 读取到的图片base64 数据编码 将此编码字符串传给后台即可 ...
- ssget使用方法
语法: (ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list]) ssget 的参数均为可选参数,需要注意的是可选参数之间的组合条件.以下语法表 ...