SWEA_7102) 준홍이의 카드놀이
SWEA
# D3
7102) 준홍이의 카드놀이 (19.10.20)
문제 링크 (SW Expert Academy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tk;
int test = Integer.parseInt(br.readLine());
for(int i=1; i<=test; i++) {
tk = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tk.nextToken());
int m = Integer.parseInt(tk.nextToken());
int[] arr = new int[n+m];
for(int p=1; p<=n; p++) {
for(int q=1; q<=m; q++) {
int sum = p+q;
arr[sum-1] = arr[sum-1]+1;
}
}
int[] copy = new int[n+m];
System.arraycopy(arr, 0, copy, 0, n+m);
Arrays.sort(copy);
int max = copy[n+m-1];
ArrayList<Integer> list = new ArrayList<>();
for(int j=0; j<n+m; j++) {
if(max==arr[j]) {
list.add(j+1);
}
}
bw.write("#" + i + " ");
for(int j: list) bw.write(j +" ");
bw.write("\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기