본문 바로가기

코딩테스트 준비/SW Expert Academy

SW Expert Academy [D2-1983] Java 풀이 : 조교의 성적 매기기

조교의 성적 매기기

 

처음 풀이

package difficulty.level02;

import java.util.Arrays;
import java.util.Scanner;

public class no1983 {
	
	/**
	 * 1983. 조교의 성적 매기기
	*/
	
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
		
		for(int test_case = 1; test_case <= T; test_case++)
		{
			int N = sc.nextInt(); //N명의 학생
			int K = sc.nextInt(); //K번째 학생 
			
			double[] score = new double[N]; //학생들 점수
			double kScore = 0; //K의 점수
			int index = 0; //K가 몇번째에 있는지
			int count = N/10;
			String sco = ""; //학점
			
			for(int i=0; i<N; i++) {
				int mid = sc.nextInt(); //중간고사 점수
				int last = sc.nextInt(); //기말고사 점수
				int work = sc.nextInt(); //과제 점수
				
				score[i] = (mid*0.35 + last*0.45 + work*0.2);
			}
			
			kScore = score[K-1];
			Arrays.sort(score);
			
			for(int i=0; i<score.length; i++) {
				if(score[i] == kScore) {
					index = i;
					break;
				}
			}
			
			index = N - index;
			if(index<= count) {
				sco = "A+";
			}else if(index>count && index <= 2*count) {
				sco = "A0";
			}else if(index>2*count && index <= 3*count) {
				sco = "A-";
			}else if(index>3*count && index <= 4*count) {
				sco = "B+";
			}else if(index>4*count && index <= 5*count) {
				sco = "B0";
			}else if(index>5*count && index <= 6*count) {
				sco = "B-";
			}else if(index>6*count && index <= 7*count) {
				sco = "C+";
			}else if(index>7*count && index <= 8*count) {
				sco = "C0";
			}else if(index>8*count && index <= 9*count) {
				sco = "C-";
			}else if(index>9*count && index <= 10*count) {
				sco = "D0";
			}
			
			System.out.printf("#%d %s\n",test_case,sco);
		}
	}
}

 

간단한 풀이 (다른 사람 코드 참고)

 

package difficulty.level02;

import java.util.Arrays;
import java.util.Scanner;

public class no1983 {
	
	/**
	 * 1983. 조교의 성적 매기기
	*/
	
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
		
		String[] grade = {"A+","A0","A-","B+","B0","B-","C+","C0","C-","D0"};
		
		for(int test_case = 1; test_case <= T; test_case++)
		{
			int N = sc.nextInt(); //N명의 학생
			int K = sc.nextInt(); //K번째 학생 
			
			double[] score = new double[N]; //학생들 점수
			double kScore = 0; //K의 점수
			int index = 0; //K가 몇번째에 있는지
			
			for(int i=0; i<N; i++) {
				int mid = sc.nextInt(); //중간고사 점수
				int last = sc.nextInt(); //기말고사 점수
				int work = sc.nextInt(); //과제 점수
				
				score[i] = (mid*0.35 + last*0.45 + work*0.2);
			}
			
			kScore = score[K-1];
			Arrays.sort(score);
			
			for(int i=0; i<score.length; i++) {
				if(score[i] == kScore) {
					index = i;
					break;
				}
			}
			
			System.out.printf("#%d %s\n",test_case,grade[(N-index-1)/(N/10)]);
		}
	}
}

 

Github 주소

https://github.com/MIN-04/CodingTest/blob/master/SW_Expert_Academy/DLevel02/no1983.java

 

MIN-04/CodingTest

코딩테스트 준비 / 문제 풀이. Contribute to MIN-04/CodingTest development by creating an account on GitHub.

github.com