Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11132    Accepted Submission(s): 4673

Problem 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
  
Author
ZHANG Zheng
  
Recommend
JGShining
 
 #include<iostream>
using namespace std; int main(){
int t;
char str[];
scanf("%d",&t);
while(t--){
scanf("%s",str);
int count=;
for(int i=;i<strlen(str);i++){
if(str[i]==str[i+])count++;
else{
if(count==) printf("%c",str[i]);
else printf("%d%c",count,str[i]);
count=;
}
}
printf("\n");
}
}
 该题同poj中3438题
http://poj.org/problem?id=3438
Look and Say
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 9179   Accepted: 5552

Description

The look and say sequence is defined as follows. Start with any string of digits as the first element in the sequence. Each subsequent element is defined from the previous one by "verbally" describing the previous element. For example, the string 122344111 can be described as "one 1, two 2's, one 3, two 4's, three 1's". Therefore, the element that comes after 122344111 in the sequence is 1122132431. Similarly, the string 101 comes after 1111111111. Notice that it is generally not possible to uniquely identify the previous element of a particular element. For example, a string of 112213243 1's also yields 1122132431 as the next element.

Input

The input consists of a number of cases. The first line gives the number of cases to follow. Each case consists of a line of up to 1000 digits.

Output

For each test case, print the string that follows the given string.

Sample Input

3
122344111
1111111111
12345

Sample Output

1122132431
101
1112131415

Source

 #include<iostream>
using namespace std; int main(){
int t;
char str[];
scanf("%d",&t);
while(t--){
scanf("%s",str);
int count=;
for(int i=;i<strlen(str);i++){
if(str[i]==str[i+])count++;
else{
printf("%d%c",count,str[i]);
count=;
}
}
printf("\n");
}
}

HDU 1020 Encoding POJ 3438 Look and Say的更多相关文章

  1. HDU 1020 Encoding 模拟

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. HDU 1020 Encoding【连续的计数器重置】

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. hdu 1020 Encoding

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Given a ...

  4. HDU 1020:Encoding

    pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  5. HDU 1815, POJ 2749 Building roads(2-sat)

    HDU 1815, POJ 2749 Building roads pid=1815" target="_blank" style="">题目链 ...

  6. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

  7. HDU 1816, POJ 2723 Get Luffy Out(2-sat)

    HDU 1816, POJ 2723 Get Luffy Out pid=1816" target="_blank" style="">题目链接 ...

  8. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

  9. hdu 1043 pku poj 1077 Eight (BFS + 康拓展开)

    http://acm.hdu.edu.cn/showproblem.php?pid=1043 http://poj.org/problem?id=1077 Eight Time Limit: 1000 ...

随机推荐

  1. 百度搜索附近加盟店等基于LBS云搜索功能的实现

    一.注册百度账号,进入开发者平台 创建应用并获取ak 地址如下 http://lbsyun.baidu.com/apiconsole/key/update?app-id=7546025 ok获取到了. ...

  2. android中跨进程通讯的4种方式

    转自:http://blog.csdn.net/lyf_007217/article/details/8542359 帖子写的很好.看来一遍,试了一遍,感觉太有意义.必须转过来! android中跨进 ...

  3. 部署sharepointform验证

    1  iis sharepoint v4 提供程序2  web service 验证提供程序3 创建web应用程序(选择基于身份验证模式,配置提供程序)4 创建网站集(空)5 创建网站集

  4. C#事件、委托简单示例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 关于OC中的几种代码延迟执行方式

    第一种: [UIView animateWithDuration:3 delay:3 options:1 animations:^{         self.btn.transform = CGAf ...

  6. C - Big Number

    Description In many applications very large integers numbers are required. Some of these application ...

  7. 从汇编看c++中全局对象和全局变量

    先来看c++源码: #include <iostream> using namespace std; class X { public: int i; public: X() : i(ii ...

  8. php 汉字排序

    <?phpheader("content-type:text/html;charset=utf-8");$array=array('重庆市','上海市','安徽省','吉林省 ...

  9. python 2.6升级到2.7

    CentOS 6.5上安装的python版本是2.6.6,不能满足我运行软件的要求,所以对python进行升级. 原以为这也就是安装个软件的事儿,在我求稳搜索一下了之后发现,也并不是那么单纯简单. 下 ...

  10. 修改Windows系统的启动Shell

    前提:当前系统中有可用的shell文件   方法: 修改当前用户的系统默认shell(只对当前用户生效,且优先于本机默认的shell) 修改“HKCU\SOFTWARE\Microsoft\Windo ...