728x90

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

 

1978번: 소수 찾기

첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.

www.acmicpc.net

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

const N = Number(input[0]);
const arr = input[1].split(' ').map(i => Number(i));
let cnt = 0;

arr.forEach((a) => {
    let flag = true;
    for (let i = 2; i < a; i++) {
        if (a % i === 0) {
            flag = false;
            break;
        }
    }
    if (a !== 1 && flag) cnt++;

})
console.log(cnt);
728x90

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

 

2754번: 학점계산

어떤 사람의 C언어 성적이 주어졌을 때, 평점은 몇 점인지 출력하는 프로그램을 작성하시오. A+: 4.3, A0: 4.0, A-: 3.7 B+: 3.3, B0: 3.0, B-: 2.7 C+: 2.3, C0: 2.0, C-: 1.7 D+: 1.3, D0: 1.0, D-: 0.7 F: 0.0

www.acmicpc.net

const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim();
const dic = {
    'A+': '4.3',
    'A0': '4.0',
    'A-': '3.7',
    'B+': '3.3',
    'B0': '3.0',
    'B-': '2.7',
    'C+': '2.3',
    'C0': '2.0',
    'C-': '1.7',
    'D+': '1.3',
    'D0': '1.0',
    'D-': '0.7',
    'F': '0.0'
}


console.log(dic[input]);
728x90

최댓값

 

2566번: 최댓값

첫째 줄에 최댓값을 출력하고, 둘째 줄에 최댓값이 위치한 행 번호와 열 번호를 빈칸을 사이에 두고 차례로 출력한다. 최댓값이 두 개 이상인 경우 그 중 한 곳의 위치를 출력한다.

www.acmicpc.net

 

내 코드

const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
let N = 0;
let M = 0;
const arr = [];
input.forEach((i) => {
    i = i.split(' ').map(a=>Number(a));
    M = i.length;
    arr.push(...i);
});

const max = Math.max(...arr);
const index = arr.indexOf(max);
console.log(max)
console.log(Math.floor(index/M) +1 , index%M +1);
728x90

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

 

1371번: 가장 많은 글자

첫째 줄부터 글의 문장이 주어진다. 글은 최대 50개의 줄로 이루어져 있고, 각 줄은 최대 50개의 글자로 이루어져 있다. 각 줄에는 공백과 알파벳 소문자만 있다. 문장에 알파벳은 적어도 하나 이

www.acmicpc.net

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

const dic = {};

input.forEach(i => {
    let arr = i.split("").filter(d => d !== ' ');
    arr.forEach((a) => {
        if(dic[a] === undefined) {
            dic[a] =1;
        } else {
            dic[a] +=1;
        }
    })
}) ;

const keys = Object.keys(dic);

let answer = [];

keys.forEach(k => {
   answer.push([k, dic[k]]);
});

answer.sort(function(a,b){
    return b[1] - a[1];
})

const max = answer[0][1];
answer = answer.filter(a => a[1] === max);

const print =[];
answer.forEach(a => {
    print.push(a[0]);
});
print.sort();

console.log(print.join(''));

+ Recent posts