[백준]25206 너의 평점은

서은경·2023년 4월 17일
0

CodingTest

목록 보기
63/71

쉬운 문제는 따로 풀이 안 적었는데 코틀린 공부할 일이 생겨서 코틀린 문법도 익힐 겸 자바/코틀린 코드를 포스팅해야겠다!

package baekjoon;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main_25206 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Map<String, Double> map = new HashMap<>();
        map.put("A+", 4.5);
        map.put("A0", 4.0);
        map.put("B+", 3.5);
        map.put("B0", 3.0);
        map.put("C+", 2.5);
        map.put("C0", 2.0);
        map.put("D+", 1.5);
        map.put("D0", 1.0);
        map.put("F", 0.0);

        int count = 20;
        double sum = 0;
        double sumScore = 0;
        for (int i = 0; i < count; i++) {
            String[] info = br.readLine().split(" ");
            double score = Double.parseDouble(info[1]);
            String grade = info[2];

            if(grade.equals("P")) continue;
            // 학점 X 과목평점 의 합을 학점의 총합으로 나눈 값
            sum += map.get(grade)*score;
            sumScore += score;
        }
        System.out.println(sum/sumScore);
    }
}
package baekjoon;

fun main() {
    val count:Int = 20
    val map:Map<String, Double> = mapOf(
            "A+" to 4.5,
            "A0" to 4.0,
            "B+" to 3.5,
            "B0" to 3.0,
            "C+" to 2.5,
            "C0" to 2.0,
            "D+" to 1.5,
            "D0" to 1.0,
            "F" to 0.0,
    )

    var sum:Double = 0.0
    var sumScore:Double = 0.0
    for(i in 0 until 20) {
        val s: String = readLine()!!
        val info = s.split(" ")
        val score: Double = info[1].toDouble()
        val grade: String = info[2]

        if(grade.equals("P")) continue
        sum += map.get(grade)!!*score
        sumScore += score
    }
    print(sum/sumScore)
}

쉬웠다! 코틀린 문법은 아직 익숙치않아서 좀 헤맸지만..

0개의 댓글

관련 채용 정보