언젠가는 펼쳐 볼 아카이브

[BOJ] 25206번 - 너의 평점은 본문

IT/Baekjoon Oline Judge

[BOJ] 25206번 - 너의 평점은

개발자희망생고롸파덕 2023. 8. 22. 17:42

사용언어: javascript - node.js

 

#제출코드

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs
  .readFileSync(filePath)
  .toString()
  .trim()
  .split('\n')
  .map((item) => item.split(' '));

solution(input);

function solution(input) {
  let totalGrade = 0;
  let majorGrade = 0;
  const degree = {
    'A+': 4.5,
    A0: 4.0,
    'B+': 3.5,
    B0: 3.0,
    'C+': 2.5,
    C0: 2.0,
    'D+': 1.5,
    D0: 1.0,
    F: 0.0,
  };

  for (let [sub, score, grade] of input) {
    if (grade === 'P') {
      continue;
    } else {
      totalGrade += +score;
      majorGrade += +score * degree[grade.trim()];
    }
  }

  console.log(majorGrade / totalGrade);
}

'IT > Baekjoon Oline Judge' 카테고리의 다른 글

[BOJ] 2566번 - 최댓값  (0) 2023.08.23
[BOJ] 2738번 - 행렬 덧셈  (0) 2023.08.22
[BOJ] 1316번 - 그룹 단어 체커  (0) 2023.08.22
[BOJ] 2941번 - 크로아티아 알파벳  (0) 2023.08.22
[BOJ] 1157번 - 단어 공부  (0) 2023.08.22