✏️ 문제(11654 / 아스키 코드 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin');
const str = input.toString();
const answer = str.charCodeAt();
console.log(answer);
✏️ 문제(11720 / 숫자의 합 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split('\n');
const N = Number(input[0]);
const numbers = input[1].split('');
let sum = 0;
for (let i = 0; i < N; i++) {
sum += Number(numbers[i]);
}
console.log(sum);
✏️ 문제(10809 / 알파벳 찾기 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin');
const answer = [];
for (let i = 97; i < 123; i++) {
answer.push(input.indexOf(String.fromCharCode(i)));
}
console.log(answer.join(' '));
✏️ 문제(2675 / 문자열 반복 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split('\n');
const T = Number(input.shift());
let answer = '';
for (let i = 0; i < T; i++) {
const N = Number(input[i][0]);
const str = input[i].split(' ')[1];
for (let j = 0; j < str.length; j++) {
answer += str.split('')[j].repeat(N);
}
answer += '\n';
}
console.log(answer);
✏️ 문제(1157 / 단어 공부 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin');
const alp = new Array(26).fill(0);
const str = input.toLowerCase();
for (let i = 0; i < input.length; i++) {
alp[str.charCodeAt(i) - 97]++;
}
const max = Math.max(...alp);
const index = alp.indexOf(max);
let isSame = false;
for (let j = 0; j < 26; j++) {
if (alp[j] == max && index != j) {
isSame = true;
break;
}
}
console.log(isSame ? '?' : String.fromCharCode(index + 65));
✏️ 문제(1152 / 단어의 개수 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim();
const answer = input.split(' ');
let cnt = 0;
for (let i = 0; i < answer.length; i++) {
if (answer[i] !== '') cnt++;
}
console.log(cnt);
✏️ 문제(2908 / 상수 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split(' ');
const A = input[0].split('').reverse().join('');
const B = input[1].split('').reverse().join('');
console.log(Math.max(A, B));
✏️ 문제(5622 / 다이얼 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split('');
input.pop();
let time = 0;
for (let i = 0; i < input.length; i++) {
let ascii = input[i].charCodeAt();
if (ascii <= 67) {
time += 3;
} else if (ascii <= 70) {
time += 4;
} else if (ascii <= 73) {
time += 5;
} else if (ascii <= 76) {
time += 6;
} else if (ascii <= 79) {
time += 7;
} else if (ascii <= 83) {
time += 8;
} else if (ascii <= 86) {
time += 9;
} else if (ascii <= 90) {
time += 10;
}
}
console.log(time);
✏️ 문제(2941 / 크로아티아 알파벳 / node.js)
📝 해답
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin").toString().trim();
let croatia = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="];
function solution(input) {
for (let alphabet of croatia) {
input = input.split(alphabet).join("*");
}
return input.length;
}
console.log(solution(input));
✏️ 문제(1316 / 그룹 단어 체커 / node.js)
📝 해답
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split('\n');
const N = Number(input.shift());
let cnt = 0;
for (let i = 0; i < N; i++) {
let word = input[i];
let arr = [];
let groupWord = true;
for (let j = 0; j < input[i].length; j++) {
if (arr.indexOf(word[j]) === -1) arr.push(word[j]);
else {
if (arr.indexOf(word[j]) !== arr.length - 1) {
groupWord = false;
break;
}
}
}
if (groupWord) {
cnt += 1;
}
}
console.log(cnt);
댓글