๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Problem Solving

[Java] ๋ฐฑ์ค€ 31577 - ๋žœ์„ฌ์›จ์–ด์™€ ๋น„ํŠธ์ฝ”์ธ

https://www.acmicpc.net/problem/31577


ํ’€์ด

15*8 = 20*6

์ฆ‰, ๋ชจ๋“  ์ข…๋ฅ˜์˜ ํŒŒ์ผ์„ ๊ฐ๊ฐ 6๊ฐœ์”ฉ ์ €์žฅํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅ

 

๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๊ตฌํ˜„ ๋ฐฉ๋ฒ• 120์นธ ์งœ๋ฆฌ ๋ฐฐ์—ด์— 1, 2, … , 19, 20 ์„ 6๋ฒˆ ์ €์žฅํ•˜๊ณ 

ํ•ด๋‹น ๋ฐฐ์—ด์„ 15๊ฐœ๋กœ ๋‚˜๋ˆ„๋ฉด ๋œ๋‹ค (๊ฐ ๋ฐฐ์—ด ์ •๋ ฌ๋„ ์žŠ์ง€ ๋ง๊ณ  ํ•˜๊ธฐ!)


์ฝ”๋“œ

๋”๋ณด๊ธฐ
๋”๋ณด๊ธฐ
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		StringBuilder sb = new StringBuilder();
		int[] arr = new int[8];

		for (int i = 0; i < 120; i++) {
			arr[i % 8] = i % 20 + 1;

			if ((i + 1) % 8 == 0) {
				Arrays.sort(arr);
				for (int j = 0; j < 8; j++) {
					sb.append(arr[j]).append((j + 1) % 8 == 0 ? '\n' : ' ');
				}
			}
		}

		System.out.println(sb);
	}
}