HDU 1020 Encoding 模拟

Encoding

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

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

水题,直接按照题意模拟就行

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
struct Node
{
    char a;
    int num;
};
vector<Node> q;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        q.clear();
        char ch[10005];
        scanf("%s",ch);
        int len=strlen(ch);
        Node tmp;
        tmp.a=ch[0];
        tmp.num=1;
        for(int i=1;i<len;i++)
        {
            if(ch[i]==tmp.a) tmp.num++;
            else
            {
                q.push_back(tmp);
                tmp.a=ch[i];
                tmp.num=1;
            }
        }
        q.push_back(tmp);
        for(int i=0;i<q.size();i++)
        {
            if(q[i].num>1)
            {
                printf("%d%c",q[i].num,q[i].a);
            }
            else printf("%c",q[i].a);
        }
        printf("\n");
    }
    return 0;
}

时间: 2024-12-16 07:09:27

HDU 1020 Encoding 模拟的相关文章

hdu 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40214    Accepted Submission(s): 17846 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

HDU 1020 Encoding 字符串

基本的字符串处理转换. 喷一喷HDU这个超级垃圾的判断系统:如果把数字存入字符串数组中输出就会错误. 如:A2B3C,如果其中的2和3保存如字符串数组中,然后输出那么就判断为WA,必须是即时输出数字2和3才算正确. 这样判我WA,哎, HDU做好点你们的判断系统吧. #include <string> #include <iostream> using namespace std; int main() { int T; string s; scanf("%d"

杭电 HDU 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29834    Accepted Submission(s): 13212 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the follow

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

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51785    Accepted Submission(s): 23041 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

HDU 1020 Encoding 字符统计

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

hdu 4964 Emmet(模拟)

题目链接:hdu 4964 Emmet 题目大意: 给定语句,按照语法翻译并输出. 解题思路:用递归模拟文法分析,主要注意几点: 括号并且的情况:(fuck)(you) 括号嵌套的情况:((fuck.you)) 优先输出id,然后是class(题目中有说) 乘法的部分:fuck*2>you*3 (每次执行fuck时,you的地方同样被执行了3次) 其他跑出样例基本没问题,具体看代码. #include <cstdio> #include <cstring> #include

HDU 4891 简单模拟

The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035    Accepted Submission(s): 355 Problem Description As a programming contest addict, Waybl is always happy to take part in vario

hdu 4194(模拟)

符合三者之一的则不满足规定,求不满足规定的个数.直接模拟. 1.被同一个人审查多次 2.被和自己同一组织的审查 3.被审查次数不等于k 代码如下: 1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-06-28 17:36 5 * Filename :

HDU 4903 (模拟+贪心)

Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 1