const { count } = require('console');
let fs = require('fs');
let path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
let input = fs.readFileSync(path).toString().trim();
function solve(input) {
let upperInput = input.toUpperCase();
let countTotal = new Array();
for (i = 65; i <= 90; i++) {
let count = 0;
if (upperInput.includes(String.fromCharCode(i))) {
for (j = 0; j < upperInput.length; j++) {
if (upperInput[j] === String.fromCharCode(i)) {
count += 1;
}
}
}
countTotal.push(count);
}
if (
countTotal.filter((value) => value === Math.max(...countTotal)).length === 1
) {
console.log(
String.fromCharCode(countTotal.indexOf(Math.max(...countTotal)) + 65)
);
} else {
console.log('?');
}
}
solve(input);
// ๋ค๋ฅธ ํ์ด๋ ๊ผญ ์ฐธ๊ณ ํด์ ์ ๋ฆฌํ ๊ฒ!
๋ค๋ฅธ ํ์ด
let input = require('fs').readFileSync('/dev/stdin').toString().toLowerCase();
const result = new Array(26).fill(0);
for (let i = 0; i < input.length; i++) {
result[input.charCodeAt(i) - 97] ++;
}
const max = Math.max(...result);
const index = result.indexOf(max);
let isSame = false;
for (let j = 0; j < 26; j++) {
if (result[j] === max && index != j) {
isSame = true;
break;
}
}
console.log(isSame ? "?" : String.fromCharCode(index + 65));
fill ์ฌ์ฉํด์ ๋ฐฐ์ด์ 0์ ์ฑ์ฐ๊ณ ๊ฐ ๋ฐฐ์ด ๊ฐ์ ํด๋นํ๋ ๊ฐ์ผ ๋ 1์ฉ ๋ํด์ฃผ๋ ๋ฐฉ๋ฒ true ์ false๋ฅผ ์กฐ๊ฑด๋ฌธ์ ์ ํ์ฉํ ์ ์์ด์ผ๊ฒ ๋ค!
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 2908 (0) | 2022.05.18 |
---|---|
[JS] 1152 (0) | 2022.05.17 |
[JS] 2675 (0) | 2022.05.17 |
[JS] 10809 (0) | 2022.05.16 |
[JS] 1065 (0) | 2022.05.15 |