akoj-1076-Encoding
Encoding
Time Limit:1000MS Memory Limit:65536K
Total Submit:62 Accepted:35
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
Sample Output
ABC
A2B3C
Source
#include <stdio.h>
#include <string.h>
#define MAXN 10000 + 10 char str[MAXN]; int main()
{ int n, i, k, c, thisn, maxn;
scanf("%d", &n);
while (n--)
{
c = 0;
scanf("%s", str);
k = strlen(str);
str[k] = -1; // 这里的输入长度小于定义的长度所以不会越界
thisn = maxn = 0;
for ( i=0; i<k; i++ ) {
thisn++;
if ( thisn > maxn ) { //实时更新段的长度
maxn = thisn;
}
if ( str[i+1] != str[i] ) { // 当后面的与前面的不同时输出之前的
thisn = 0;
if ( maxn == 1 ) {
printf("%c", str[i]);
}
else {
printf("%d%c", maxn, str[i]);
maxn = 0; // 输出后将最大长度再次赋值为0
}
}
} printf("\n");
} return 0;
}
akoj-1076-Encoding的更多相关文章
- javac -encoding utf8 in linux
由于另外负责编码的同事用的是utf-8,我用的默认的编码格式gbk,在提交代码时,为了迁就他,我打算把格式用工具转成utf-8. 转化成果后,然后在make一下,发现javac -encoding u ...
- 创建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 ...
- Node.js Base64 Encoding和Decoding
如何在Node.js中encode一个字符串呢?是否也像在PHP中使用base64_encode()一样简单? 在Node.js中有许多encoding字符串的方法,而不用像在JavaScript中那 ...
- java Properties异常:Malformed \uxxxx encoding.
昨天项目中遇到一个 java.lang.IllegalArgumentException: Malformed \uxxxx encoding.这样的一个异常,debug了一下发现是读取propert ...
- svn: Can't convert string from 'UTF-8' to native encoding 的解决办法(转)
http://www.cnblogs.com/xuxm2007/archive/2010/10/26/1861223.html svn 版本库中有文件是以中文字符命名的,在 Linux 下 check ...
- C# 字符编码类Encoding
在网络通信中,很多情况下都是将字符信息转成字节序列进行传输.将字符序列转为字节序列的过程称为编码.当这些字节传送到接收方,接收方需要逆向将字节序列转为字符序列.这个过程就是解码. 常见编码有ASCII ...
- 字符集和字符编码(Charset & Encoding)
字符集和字符编码(Charset & Encoding)[转] 1.基础知识 计算机中储存的信息都是用二进制数表示的:而我们在屏幕上看到的英文.汉字等字符是二进制数转换之后的结果.通俗的说,按 ...
- 使用英文版eclipse保存代码,出现some characters cannot be mapped using "Cp1251" character encoding.
some characters cannot be mapped using "Cp1251" character encoding. 解决办法:方案一: eclipse-> ...
- <?xml version="1.0" encoding="UTF-8"?> 的作用?
version="1.0" 声明用的xml版本是1.0 encoding="UTF-8" 声明用xml传输数据的时候的字符编码,假如文档里面有中文,编码方式不是 ...
- 关于Unicode和URL encoding入门的一切以及注意事项
本文同时也发表在我另一篇独立博客 <关于Unicode和URL encoding入门的一切以及注意事项>(管理员请注意!这两个都是我自己的原创博客!不要踢出首页!不是转载!已经误会三次了! ...
随机推荐
- javascript实现禁止右键和F12查看源代码
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- java udp服务器设计源码
根据个人理解写的,轻喷. 没什么大的逻辑,直接上代码. UDPServer.java package mySocket;/* * 服务器端 */import java.awt.GridLayout;i ...
- MyBatis基础
一.大配置 <?xml version="1.0" encoding="UTF-8" ?> <!--文档类型,头文件--> <!D ...
- 记一次SAP新业务开发项目
直到笔者写这篇博文的时候,这个开发项目名义上已经上线,但其实开发以及优化的工作还在继续,数据的修复也仍在继续... IT系统环境很简单,一个基于JAVA+Mysql的Web平台,一个是宇宙第一的SAP ...
- input file 上传图片问题
html代码如下: <input id="fileup" type="file" accept="image/*" capture=& ...
- [基础架构]PeopleSoft Process Scheduler 重要文件说明
我们都知道PeopleSoft是由几个不同的服务组成的,他们在PeopleSoft体系结构中扮演着自己的角色.这些服务具有不同的文件结构并包含重要的可执行文件和配置文件. 以下是Peoplesoft体 ...
- dict-字典功能介绍
叨逼叨:#字典 可变类型 意思就是修改的是自己本身#可变类型,当修改后,内存里的值也会对应着修改#不可变类型,当修改后,会在内存里开启一块新的空间,放新的值#1.清空 # name = { # 'na ...
- mongoDB 学习笔记纯干货(mongoose、增删改查、聚合、索引、连接、备份与恢复、监控等等)
最后更新时间:2017-07-13 11:10:49 原始文章链接:http://www.lovebxm.com/2017/07/13/mongodb_primer/ MongoDB - 简介 官网: ...
- 扩展SQLite使其能从apk文件中读取db
游戏中会大量使用到配置文件,每个项目组根据自己不同的需求会选择不同的存储格式,比如使用Json或者SQLite来存储数据.此处我们只对使用SQLite的情况来做讨论.一般情况下会选择把它放在可读写目录 ...
- 关于abp中使用的sweetalert对话框组件的confirm确认对话框中的一个坑
今天修改了一个功能,限制删除用户,在删除的时候不满足条件的时候提示用户原因,使用的sweet alert组件. abp框架前端集成了sweet alert 对http请求的error做了全局处理,我在 ...