JLH Statistical Method Statistical Flying Dragon (C++) kkmd66

Description:

Because the Dragon King Alpha has the natural ability to control the mind of the dragons, where Alpha often goes, there will be all kinds of dragons flying around it.

Now, as Hiccup, the brave young Viking warrior, you wonder just how many dragons surround Alpha. The problem is as follows: you are given a string consisting of "AZ" representing different types of dragons. For example "BCABCA", you need to use JHL statistics to count the number of each letter, that is, output the number of each letter before the letter, for example, the answer is "2A2B2C". (The answer is output in lexicographical order, that is, the answer cannot be 2B2C2A)

Input:

第一行输入一个T(T<=500)表明有T组测试样例,

在每个测试样例中,输入一个字符串,不超过1000个字母,保证都为大写字母

Output:
For each test example, the output occupies one line, and the output results are described above

Sample Input:

1
ABCABC

Sample Output:

2A2B2C

#include <iostream>
#include "map"
#include "string"

using namespace std;

/**
 * kkmd66
 * @return 
 */

int main() {
    
    

    int T;
    cin >> T;

    for (int i = 0; i < T; ++i) {
    
    

        string str;
        cin >> str;

        //存储
        map<char, int> comp;
        for (int j = 0; j < str.size(); ++j) {
    
    
            if (comp.find(str.at(j)) != comp.end()) {
    
    
                comp.find(str.at(j))->second++;
            } else
                comp.insert(make_pair(str.at(j), 1));
        }

        //输出
        for (auto it = comp.begin(); it != comp.end(); it++) {
    
    
            cout<<it->second<<it->first;
        }
        cout<<endl;
    }

    return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324098860&siteId=291194637