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 ...
随机推荐
- Linux 导出Okular 编辑的pdf批注
1.环境 ubuntu 14.04 LTS Okular Version 0.19.3 Using KDE Development Platform 4.13.3 2.方法 2.1只导出批注,不改变p ...
- 自定义view(13)自定义属性
1.添加attrs.xml文件 在android studio下,在res/values 下新建资源文件attrs.xml 2.添加自定义的属性 在attrs.xml中添加属性,如下.其中format ...
- 18.3.2从Class上获取信息(内部类接口等)
内部类 接口.枚举.注释类型
- XON/OFF
#define XON 0x11#define XOFF 0x13查找ASCII码表,这两个对应的是DC1(设备控制1)和DC3(设备控制3) X/ON和X/OFF为开启和关闭发送器的信号.X /ON ...
- Camera和 tris,verts的优化
Unity的Camera组件有很多可调节的参数,当需要做优化的时候,stats面板中的tris和verts这两个重点项都与Camera组件的参数有很大关系,有些参数的意义Unity手册说得不够详细,经 ...
- P3717 [AHOI2017初中组]cover
题目背景 以下为不影响题意的简化版题目. 题目描述 一个n*n的网格图上有m个探测器,每个探测器有个探测半径r,问这n*n个点中有多少个点能被探测到. 输入输出格式 输入格式: 第一行3个整数n,m, ...
- NIO服务端主要创建过程
NIO服务端主要创建过程: 步骤一:打开ServerSocketChannel,用于监听客户端的连接,它是所有客户端连接的副管道,示例代码如下: ServerSocketChannel ...
- 获取第三方软件的包名、入口Activity的类名
要启动指定的第三方软件,需要知道第三方软件的包名.类名. 获取第三方软件包名.类名的两种方法: 1.使用aapt aapt是sdk自带一个工具,在 Sdk\builds-tools 目录下 .如果没有 ...
- (转)使用CGLIB实现AOP功能与AOP概念解释
http://blog.csdn.net/yerenyuan_pku/article/details/52864395 使用CGLIB实现AOP功能 在Java里面,我们要产生某个对象的代理对象,这个 ...
- Python 中print 和return 的区别
1.print() print()函数的作用是输出数据到控制台,就是打印在你能看到的界面上. 2.return return语句[表达式]退出函数,选择性地向调用方返回一个表达式.不带参数值的retu ...