/* 문제설명 */

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

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

로그인을 해야만 볼 수 있다.

 

 


 

/* 해답코드 */

package samsung;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Flatten {
	static int[] boxes = new int[100];
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = null;
		int ans=0;
		for(int i=0;i<10;i++) {
			int n = Integer.parseInt(br.readLine());
			st = new StringTokenizer(br.readLine());
			for(int j=0;j<100;j++) {
				boxes[j] = Integer.parseInt(st.nextToken());
			}
			
			for(int j=0;j<n;j++) {
				int max = boxes[0];
				int min = boxes[0];
				int maxIdx = 0;
				int minIdx = 0;
				for(int k=0;k<100;k++) {
					if(max<boxes[k]) {
						max=boxes[k];
						maxIdx = k;
					}
						
					if(min>boxes[k]) {
						min=boxes[k];
						minIdx = k;
					}
				}
				boxes[maxIdx]--;
				boxes[minIdx]++;
			}
			
			int max = boxes[0];
			int min = boxes[0];
			for(int k=0;k<100;k++) {
				if(max<boxes[k]) {
					max=boxes[k];
				}
					
				if(min>boxes[k]) {
					min=boxes[k];
				}
			}
			ans = max - min;
			System.out.printf("#%d %d\n",i+1,ans);
			
		}
	}
}

'Coding Test > SWEA' 카테고리의 다른 글

[SWEA][1251]하나로  (0) 2021.08.25
[SWEA]Ladder1  (0) 2021.08.05

+ Recent posts