题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
let input = await readline();
input = input.split("");
let map = new Map();
for (let e of input) {
if (map.has(e)) {
map.set(e, map.get(e) + 1);
} else {
map.set(e, 1);
}
}
// console.log(map);
let mapArray = Array.from(map.entries());
// console.log(mapArray);
mapArray.sort((a, b) => {
if(a[1] === b[1]){
return a[0].localeCompare(b[0])
}
else{
return b[1] - a[1]
}
}
)
let res = mapArray.map((e) => e[0]).join('')
console.log(res)
})();
上海得物信息集团有限公司公司福利 1263人发布