https://www.acmicpc.net/problem/10808

 

10808번: 알파벳 개수

단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split("");
const answer = [];

const dic = {
    a: 0,
    b: 0,
    c: 0,
    d: 0,
    e: 0,
    f: 0,
    g: 0,
    h: 0,
    i: 0,
    j: 0,
    k: 0,
    l: 0,
    m: 0,
    n: 0,
    o: 0,
    p: 0,
    q: 0,
    r: 0,
    s: 0,
    t: 0,
    u: 0,
    v: 0,
    w: 0,
    x: 0,
    y: 0,
    z: 0,
}

input.forEach((d) => {
    if(dic[d] !== undefined ) dic[d]++;
});

const keyList = Object.keys(dic);

keyList.forEach((key) => {
    answer.push(dic[key]);
});

console.log(answer.join(" "));
728x90

https://www.acmicpc.net/problem/2744

 

2744번: 대소문자 바꾸기

영어 소문자와 대문자로 이루어진 단어를 입력받은 뒤, 대문자는 소문자로, 소문자는 대문자로 바꾸어 출력하는 프로그램을 작성하시오.

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split("");

input.forEach((i, index) => {
    if(i.charCodeAt() >= 65 && i.charCodeAt() <= 90) {
        input[index] = String.fromCharCode(i.charCodeAt()+32);
    } else {
        input[index] = String.fromCharCode(i.charCodeAt()-32);
    }
})

console.log(input.join(""));
728x90

https://www.acmicpc.net/problem/2750

 

2750번: 수 정렬하기

첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");

const N = Number(input[0]);
const list = [];

for(let i= 0; i < N ; i++) {
    list.push(Number(input[1+i]));
}

list.sort();
list.forEach((l) => {
    console.log(l);
});
728x90

https://www.acmicpc.net/problem/1316

 

1316번: 그룹 단어 체커

그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");

const N = Number(input[0]);
let answer = 0;

for(let i = 0 ; i < N ; i++) {
    let cnt = 0;
    let view = [];
    const tmp = input[i+1].split("");
    let prev = '';
    tmp.forEach((t, index) => {
        if(index === 0) prev = t;
        if(prev !== t && !view.includes(t)) {
            view.push(prev);
            prev = t;
        }
        if(view.includes(t)) {
            cnt++;
        }
    });
    if(cnt > 0) answer++; 
}

console.log(N-answer);
728x90

+ Recent posts