View Code of Problem 36

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

using namespace std;

/**
 * kkmd66 四刷
 * @return 
 */

int main() {

    int T;
    cin >> T;
    while (T--) {
        string str;
        cin >> str;
        map<char, int> result;
        //依次找
        while (str.size() != 0) {
            //第一个字符
            char temp = str[0];
            //计数
            int count = 1;
            for (int i = 1; i < str.size(); ++i) {
                if (temp == str[i]) {
                    count++;
                    str[i] = '#';
                }
            }
            str.erase(0, 1);
            //存储答案
            result.insert(make_pair(temp, count));
        }
        //输出
        for (auto it: result) {
            if (isalpha(it.first))
                cout << it.second << it.first;
        }
        cout << endl;
    }
    return 0;

}

Double click to view unformatted code.


Back to problem 36