https://www.acmicpc.net/problem/25206
25206๋ฒ: ๋์ ํ์ ์
์ธํ๋ํ๊ต ์ปดํจํฐ๊ณตํ๊ณผ๋ฅผ ์กธ์ ํ๊ธฐ ์ํด์๋, ์ ๊ณตํ์ ์ด 3.3 ์ด์์ด๊ฑฐ๋ ์กธ์ ๊ณ ์ฌ๋ฅผ ํต๊ณผํด์ผ ํ๋ค. ๊ทธ๋ฐ๋ฐ ์๋ฟ์ธ, ์นํ์ด๋ ๊น๋นกํ๊ณ ์กธ์ ๊ณ ์ฌ๋ฅผ ์์ํ์ง ์์๋ค๋ ์ฌ์ค์ ๊นจ๋ฌ์๋ค! ์น
www.acmicpc.net
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double score = 0; // ๊ณผ๋ชฉํ์
double credit = 0; // ํ์
double sum = 0; // ํ์ ์ ์ดํฉ
double all = 0; // (ํ์ × ๊ณผ๋ชฉํ์ )์ ํฉ
double answer = 0;
for (int i = 0; i < 20; i++) {
String n = sc.nextLine();
String[] arr = n.split(" ");
credit = Double.parseDouble(arr[1]);
switch (arr[2]) {
case "A+" -> score = 4.5;
case "A0" -> score = 4.0;
case "B+" -> score = 3.5;
case "B0" -> score = 3.0;
case "C+" -> score = 2.5;
case "C0" -> score = 2.0;
case "D+" -> score = 1.5;
case "D0" -> score = 1.0;
case "F" -> score = 0.0;
case "P" -> credit = 0.0;
}
sum += credit;
all += credit * score;
}
answer = all / sum;
if (all == 0) {
answer = 0;
}
System.out.println(answer);
}
}