(TOJ1248)Encoding
描述
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.
输入
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.
输出
For each test case, output the encoded string in a line.
样例输入
2 ABC ABBCCC
样例输出
ABC A2B3C
1 #include <stdio.h> 2 #include <math.h> 3 #include <ctype.h> 4 #include <string.h> 5 6 char a[10001]; 7 8 void deal(char *s){ 9 int i,j,k; 10 int L,count=0; 11 i=0; 12 L=strlen(s); 13 while(i<L){ 14 j=i+1; 15 if(s[i]!=s[j]){ 16 printf("%c",s[i]); 17 18 }else{ 19 k=j+1; 20 count+=2; 21 while(s[k]==s[j]){ 22 k++;count++; 23 } 24 printf("%d%c",count,s[j]); 25 count=0; 26 i=k-1; 27 } 28 i++; 29 } 30 printf("\n"); 31 } 32 33 void solve(){ 34 int n; 35 scanf("%d",&n); 36 getchar(); 37 while(n--){ 38 gets(a); 39 deal(a); 40 } 41 } 42 43 44 int main(){ 45 solve(); 46 return 0; 47 }
转载于:https://www.cnblogs.com/xueda120/archive/2013/05/22/3093197.html
(TOJ1248)Encoding相关推荐
- python爬虫实例(urllibBeautifulSoup)
python 2.7.6 urllib:发送报文并得到response BeautifulSoup:解析报文的body(html) #encoding=UTF-8 from bs4 import Be ...
- python基础教程--代码集合(下)
文章目录 38.字典dict 38.1 创建字典 38.2 字典获取元素 38.3 key字典 38.4key-value-items键值对 38.5字典的遍历 38.6 哈希函数haxi 39.可变 ...
- 深入学习Redis(1):Redis内存模型
前言 Redis是目前最火爆的内存数据库之一,通过在内存中读写数据,大大提高了读写速度,可以说Redis是实现网站高并发不可或缺的一部分. 我们使用Redis时,会接触Redis的5种对象类型(字符串 ...
- Linux 命令(34)—— vim 命令
文章目录 1.简介 2.命令格式 3.选项说明 4.内置命令 5.vim 需知 5.1 vim 的四大模式 5.2 vim 相关编码选项 5.3 vim 读写文件时编码转换过程 6.vim 常见用法 ...
- Python数据类型(3)
字符串(str): 单引号''.双引号""嵌套使用,可以不使用转义字符:'abc"dd"ef'."acc'd'12",字符串不可以是多行的 ...
- 深入学习 Redis(1):Redis 内存模型
前言 Redis是目前最火爆的内存数据库之一,通过在内存中读写数据,大大提高了读写速度,可以说Redis是实现网站高并发不可或缺的一部分. 我们使用Redis时,会接触Redis的5种对象类型(字符串 ...
- Django的视图函数(二):request对象、视图函数返回值(HTML响应、JsonResponse)、反向解析(视图函数)、HttpResponse子类
文章目录 一.request对象 1.概念 2.属性 (1)path (2)method (3)GET (4)POST (5)encoding (6)META 二.视图函数的返回值 1.HTML响应 ...
- EBCDIC 与 GBK 的字符编码及其转换(转)
概览 有些用户在使用 AIX 时在字符编码方面遇到一些困惑,请看下面的场景: 1,用户用从 AIX 利用 FTP 客户端登录上 IBM i,切换到某个 Library/File,然后 get 其中的某 ...
- 基础地理信息术语(a-b-c-d-e-f-g-h-i-k-l-m-n-o-t-u-v-w-x-y-z)
基础地理信息术语(a-b-c-d-e-f-g-h-i-k-l-m-n-o-t-u-v-w-x-y-z) absolute reference frame 绝对参考坐标系 adjacency analy ...
最新文章
- java list addall源码_Java集合:ArrayList源码分析
- mit oracle hd120,【出】MIT Oracle Matrix HD100 喇叭线 10呎
- 进击的docker 二 : docker 快速入门
- 服务器端密钥库文件,使用密钥库文件为SOAP运行客户端WS
- adf.test_在ADF 12.2.1.3中使用基于JSON的REST Web服务
- mysql管理节点_MySql节点管理安装步骤需要在SerA和SerB上各做一次
- endnotex9如何导入caj中文文献_EndNote X9常用方法汇总
- Mac下搭建手机APP开发环境(HBuilder X ,HTML5plus Runtime,MUI,springboot)
- 8 一点就消失_农村即将消失的15个“老物件”,件件充满回忆,全认识说明你老了...
- flask-前端-requests之response对应关系 text
- (转载)VS2010/MFC编程入门之五十二(Ribbon界面开发:创建Ribbon样式的应用程序框架)...
- 拓端tecdat|Matlab通过市场数据校准Hull-White利率模型参数
- Atheros QCA8337交换芯片驱动开发
- Java输入/输出流(1)
- 苹果电脑写python体验好吗_苹果笔记本系统好用吗,浅谈Mac的优缺点
- 快手也抢先字节出手了…
- okhttp使用总结
- Eclipse 基本 java lombok maven 示例
- java 测试网速_java心跳测网速Demo
- BugkuCTF-Crypto题python_jail
热门文章
- oracle10g 64位安装包下载地址,Oracle10g下载地址--多平台下的32位和64位
- java openresty 调用_Openresty使用zlib解压缩response body
- KB-QA:如何对问题进行信息抽取?
- 深度学习训练和推理有何不同?
- XDeepFM 模型,字节跳动短视频内容理解和推荐系统
- 液晶拼接处理器_液晶拼接屏方案的制作和规划
- resnet预训练模型_干货 | NLP中的十个预训练模型
- spring boot 配置网关时404错误_Kong中使用grpcweb插件代理grpc服务时遇到的坑
- 《MFC游戏开发》笔记四 键盘响应和鼠标响应:让人物动起来
- Ubuntu gitweb 安装配置