Encoding编码 18
2015-11-25 20:27
162 查看
Encoding编码
Problem Description
Given a stringcontaining 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.
由于仅包含“A”的字符串 - 'Z',我们可以用下面的方法对其进行编码:
包含k个相同的字符1.各子串应当被编码为“的kX”,其中“X”是在该子串的唯一的字符。
2.如果子串的长度为1,'1'应该被忽略。
Input
The first linecontains an integer N (1 <= N <= 100) which indicates the number of testcases. The next N lines contain N strings. Each string consists of only 'A' -'Z' and the length is less than 10000.
第一行包含一个整数N(1<= N<=100)表示测试用例的数量。接下来的N行包含N个字符串。每个字符串仅由'A' - 'Z'和长度小于10000。
Output
For each testcase, output the encoded string in a line.
对于每个测试用例,输出线路编码字符串
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
代码如下:
Problem Description
Given a stringcontaining 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.
由于仅包含“A”的字符串 - 'Z',我们可以用下面的方法对其进行编码:
包含k个相同的字符1.各子串应当被编码为“的kX”,其中“X”是在该子串的唯一的字符。
2.如果子串的长度为1,'1'应该被忽略。
Input
The first linecontains an integer N (1 <= N <= 100) which indicates the number of testcases. The next N lines contain N strings. Each string consists of only 'A' -'Z' and the length is less than 10000.
第一行包含一个整数N(1<= N<=100)表示测试用例的数量。接下来的N行包含N个字符串。每个字符串仅由'A' - 'Z'和长度小于10000。
Output
For each testcase, output the encoded string in a line.
对于每个测试用例,输出线路编码字符串
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
代码如下:
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ // const int MAXN=10005; char a[10005]; int main() { int i,temp; int T; scanf("%d",&T);//两组测试数据 while(T--) { scanf("%s",&a);//输入的是字符串 i=0; while(a[i]!='\0')//这是判断字符串结束的标志 { temp=i; while(a[temp+1]==a[i]) { temp++; } if(temp>i) printf("%d",temp-i+1); printf("%c",a[i]); i=temp; i++; } printf("\n"); } return 0; }
相关文章推荐
- LinearLayout的android:layout_weight的真实含义
- 在linux中的virtualbox无法挂载usb设备的解决方法
- 计算器的封装
- 设计模式5—单件模式
- snort 之 ProcessTcp()
- 常用的python随机数
- 《leetCode》:Linked List Cycle
- cf 599 C (模拟+STL)
- 我的android之旅
- SPark pipeline学习
- Node.js + Express + Mongodb 开发搭建个人网站(一)
- HEVC算法和体系结构:预测编码之帧间预测
- HEVC算法和体系结构:预测编码之帧间预测
- codeforces 602 D. Lipshitz Sequence (单调栈)
- HDU_1213
- UVa 1344 - Tian Ji -- The Horse Racing
- Least Common Multiple最小公倍数 17
- Java的一些引用方面的问题
- eclipse快捷键
- 截图