描述
对于给定的由小写字母和数字构成的字符串 s,统计出现的每一个字符的出现次数,按出现次数从多到少排序后依次输出。特别地,如果出现次数相同,则按照 ASCII 码由小到大排序。
输入描述:
在一行上输入一个长度为 1≦len(s)≦103、由小写字母和数字构成的字符串 s。
输出描述:
在一行上输出一个字符串,代表按频次统计后的结果。
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
line = await readline();
let map = new Map([]);
for (let i = 0; i < line.length; i++) {
map.set(line[i], map.get(line[i]) + 1 || 1);
}
const arr = [...map].sort((a, b) =>
b[1] !== a[1] ? b[1] - a[1] : a[0].charCodeAt(0) - b[0].charCodeAt(0)
);
console.log(arr.map((i) => i[0]).join(""));
})();