hdu 1020

这道题的关键是理解题意:输入ABCDC,输出ABCDC,而不是AB2CD。

#include <iostream>
using namespace std;
//char a[]={‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,‘G‘,‘H‘,‘I‘,‘J‘,‘K‘,‘L‘,‘M‘,‘N‘,‘O‘,‘P‘,‘Q‘,‘R‘,‘S‘,‘T‘,‘U‘,‘V‘,‘W‘,‘X‘,‘Y‘,‘Z‘};
//ABCDC就是ABCDC不是AB2CD
void fun(string s)
{

}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int len=s.length();
        int res=1;s[len]=‘0‘;
        for(int i=0;i<len;i++)
        {
            if(s[i]==s[i+1])
                res++;
            else
            {
                if(res==1)
                    cout<<s[i];
                else if(res>1)
                    cout<<res<<s[i];
                res=1;//res要记得重置!!!
            }
        }
        cout<<endl;
    }
    return 0;
}

res忘记重置了!!! 循环中要 记得重置!!!

时间: 2024-11-05 15:12:46

hdu 1020的相关文章

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): 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): 25691    Accepted Submission(s): 11289 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): 39047    Accepted Submission(s): 17279 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

杭电 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,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. 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 c

[2016-01-21][HDU][1878]

/************************************************************* 时间:2016-01-20  15:00:34  星期三 题目编号:G HDU 1878 题目大意:给定一个图,判断是否是欧拉图 方法:         1.度数是偶数        2.连通量为1 判断连通量 可以 用 并查集 也可以dfs 解题过程遇到问题: *******************************************************