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 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

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<sstream>
#include<queue>
#include<cmath>
#include<list>
#include<vector>
#include<string>
using namespace std;
#define long long ll
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 500005;
int n, m, tot;
int a[N];

map<string,int> mp;
int main()
{
    int t;
    cin >> t;
    string s;
    while(t--)
    {
        int c = 1;
        cin >> s;
        for(int i=0; i<s.size(); i++)
        {
            if(s[i+1]==s[i]){
                c++;
            }
            else{
                if(c==1){
                    printf("%c",s[i]);
                    c = 1;
                }
                else{
                    printf("%d%c",c,s[i]);
                    c = 1;
                }
          }

       }
       cout<<endl;
    }
}

原文地址:https://www.cnblogs.com/Roni-i/p/8712162.html

时间: 2024-10-29 13:04:22

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 字符统计

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 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 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 1231 最大连续子序列 DP题解

典型的DP题目,增加一个额外要求,输出子序列的开始和结尾的数值. 增加一个记录方法,nothing special. 记录最终ans的时候,同时记录开始和结尾下标: 更新当前最大值sum的时候,更新开始节点. const int MAX_N = 10001; long long arr[MAX_N]; int N, sta, end; long long getMaxSubs() { long long sum = 0, ans = LLONG_MIN; int ts = 0; for (int

[ACM] hdu 1231 最大连续子序列 (动规复习)

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17687    Accepted Submission(s): 7828 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j

HDU 1231 最大连续子序列 --- 入门DP

HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #include <cstdio> #include <cstring> int dp[10005]; int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endif int n

HDU 1231——最大连续子序列(DP)

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18603    Accepted Submission(s): 8268 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j