๐Ÿ“š ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๋ฐฑ์ค€ & ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[SWEA][JAVA]D3 : ์ค€ํ™์ด์˜ ์นด๋“œ๋†€์ด

deep_lee 2022. 11. 16. 15:40

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AWkIlHWqBYcDFAXC&categoryId=AWkIlHWqBYcDFAXC&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=3 

 

SW Expert Academy

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

swexpertacademy.com

 

 


a๋ถ€ํ„ฐ b์‚ฌ์ด์˜ ๋ชจ๋“  ๊ฐ’์˜ ํ•ฉ๋“ค์„ ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ด index๋ฅผ ๋งŒ๋“ค๊ณ ,

๊ฐ ํ•ฉ๋“ค์„ ๋ฐฐ์—ด์˜ index๊ฐ’์„ ์ฆ๊ฐ€์‹œ์ผœ์„œ ์–ด๋–ค ํ•ฉ์ด ์ œ์ผ ๋งŽ์ด ๋“ฑ์žฅํ–ˆ๋Š”์ง€ max๋ฅผ ์ด์šฉํ•ด ๋น„๊ตํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  max์™€ ๊ฐ™์€ ๊ฐ’๋“ค์˜ index๋ฅผ ์ถœ๋ ฅ.

 

 

 

import java.util.Scanner;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int a=kb.nextInt();
            int b=kb.nextInt();
            int[] index=new int[a+b+1];

            for(int i=1; i<=a; i++){
                for(int j=1; j<=b; j++){
                    index[i+j]++;
                }
            }
            int max=0;
            for(int i=2; i<index.length; i++){
                if(index[i]>max){
                    max=index[i];
                }
            }
            System.out.print("#"+t+" ");
            for(int i=0; i<index.length; i++){
                if(index[i]==max)
                    System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}