# 28. 字符串摘要

28

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function(line) {
    line = line.toLowerCase();
    const charCount = {};
    let sb = '';
    for(let i=0; i<line.length; i++) {
        if (line[i] >= 'a' && line[i] <= 'z') {
            charCount[line[i]] = charCount[line[i]] ? (charCount[line[i]] + 1) : 1;
            sb += line[i];
        }
    }
    let ans = [];
    let pre = line[0];
    let repeat = 1;
    charCount[pre] = charCount[pre] - 1;
    for(let i=1; i<line.length; i++) {
        const cur = line[i];
        charCount[pre] = charCount[pre] - 1;
        if (cur === pre) {
            repeat++;
        } else {
            ans.push(pre + (repeat > 1 ? repeat : charCount[pre]));
            pre = cur;
            repeat = 1;
        }
    }
    ans.sort((a, b) => {
        if (a[a.length - 1] !== b[b.length - 1]) {
            return b[b.length - 1] - a[a.length - 1]
        } else {
            return a[0] - b[0];
        }
    });
    let res = '';
    for(const an of ans) {
        res += an;
    }
    console.log(res);
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45