๐ŸŽฏ Coding Test

SWEA 1204. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - ์ตœ๋นˆ์ˆ˜ ๊ตฌํ•˜๊ธฐ

์—ฐ_์šฐ๋ฆฌ 2022. 2. 10. 14:20
๋ฐ˜์‘ํ˜•
 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 

 

 

ํ’€์ด์ฝ”๋“œ

import java.util.*;
import java.io.FileInputStream;

class Solution
{
	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 testNum = sc.nextInt();
            //System.out.println(testNum + "๋ฒˆ์งธ");
         
        	int[] scoreArr = new int[1000];	
         	int[] scoreCountArr = new int[101];	//0๋„ ํฌํ•จํ•ด์•ผํ•จ
            
         	//์ ์ˆ˜ ๋“ฑ์žฅํšŸ์ˆ˜ ์ž…๋ ฅ
         	for(int i=0; i<1000; i++){
                int score = sc.nextInt();
                scoreArr[i] = score;
            	scoreCountArr[score] = scoreCountArr[score] +1;
            }
         
         
         	//์ ์ˆ˜ ๋“ฑ์žฅํšŸ์ˆ˜์˜ ์ตœ๋Œ€๊ฐ’ ๊ตฌํ•˜๊ธฐ
         	int max = 0;
            //์ ์ˆ˜ ๋“ฑ์žฅํšŸ์ˆ˜์˜ ์ตœ๋Œ€๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” ์ˆซ์ž ๊ฐ€์ ธ์˜ค๊ธฐ
         	int result = 0;
         	for(int i=100; i>=0; i--){
                if(scoreCountArr[i] > max){
                    max = scoreCountArr[i];
                    result = i;
                }
            }
            System.out.println("#" + testNum + " " + result);

		}
	}
}
๋ฐ˜์‘ํ˜•
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ํŠธ์œ„ํ„ฐ ๊ณต์œ ํ•˜๊ธฐ
  • ๊ตฌ๊ธ€ ํ”Œ๋Ÿฌ์Šค ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜คํ†ก ๊ณต์œ ํ•˜๊ธฐ