44import java .util .StringTokenizer ;
55
66public class _12034 {
7+
78 public static void main (String [] args ) throws IOException {
89 BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
910 BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
1011 StringBuilder sb = new StringBuilder ();
1112 StringTokenizer st ;
1213
13- int testCase = Integer .parseInt (br .readLine ());
14- int x = 1 ;
14+ int testCases = Integer .parseInt (br .readLine ());
1515
16- while ( testCase --> 0 ) {
16+ for ( int t = 1 ; t <= testCases ; t ++ ) {
1717 int n = Integer .parseInt (br .readLine ());
1818
19- int [] arr = new int [2 * n ];
20- int [] result = new int [n ];
21- boolean [] visited = new boolean [2 * n ];
19+ int [] prices = new int [2 * n ];
20+ int [] discountPrices = new int [n ];
21+ boolean [] used = new boolean [2 * n ];
2222
2323 st = new StringTokenizer (br .readLine ());
24-
25- for (int i = 0 ; i < 2 * n ; i ++) {
26- arr [i ] = Integer .parseInt (st .nextToken ());
24+ for (int j = 0 ; j < 2 * n ; j ++) {
25+ prices [j ] = Integer .parseInt (st .nextToken ());
2726 }
2827
2928 int index = 0 ;
3029
31- for (int i = 0 ; i < 2 * n ; i ++) {
32- if (index == n ) {
33- break ;
34- }
35-
36- // 방문 했거나, 정상 가격인 경우
37- if (visited [i ] || arr [i ] % 3 != 0 ) {
30+ for (int i = 0 ; i < 2 * n && index < n ; i ++) {
31+ // 방문했거나, 정상 가격인 경우
32+ if (used [i ] || prices [i ] % 3 != 0 ) {
3833 continue ;
3934 }
4035
41- long temp = (arr [i ] / 3L ) * 4 ; // 정상 가격
36+ long originalPrice = (prices [i ] / 3L ) * 4 ;
4237
4338 for (int j = i + 1 ; j < 2 * n ; j ++) {
44- if (!visited [j ] && arr [ j ] == temp ) {
45- visited [j ] = true ;
46- result [index ] = arr [i ]; // 할인 가격 저장
39+ if (!used [j ] && originalPrice == prices [ j ] ) {
40+ used [j ] = true ;
41+ discountPrices [index ] = prices [i ];
4742 index ++;
48-
4943 break ;
5044 }
5145 }
5246 }
5347
54- sb .append ("Case #" ).append (x ).append (": " );
48+ sb .append ("Case #" ).append (t ).append (": " );
5549
56- for (int i : result ) {
57- sb .append (i ).append (" " );
50+ for (int val : discountPrices ) {
51+ sb .append (val ).append (" " );
5852 }
5953
6054 sb .append ("\n " );
61- x ++;
6255 }
6356
6457 bw .write (sb .toString ());
6558 bw .flush ();
6659 bw .close ();
6760 }
61+
6862}
0 commit comments