File tree Expand file tree Collapse file tree 2 files changed +29
-28
lines changed
Expand file tree Collapse file tree 2 files changed +29
-28
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 296016 KB, 시간: 820 ms
7+ 메모리: 294504 KB, 시간: 724 ms
88
99### 분류
1010
11- 자료 구조, 구현 , 큐
11+ 구현, 자료 구조, 큐
1212
1313### 제출 일자
1414
15- 2024년 10월 23일 09:47:36
15+ 2025년 12월 19일 11:35:04
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1- import java .util .*;
21import java .io .*;
2+ import java .util .*;
33
44public class Main {
5- public static void main (String [] args ) throws IOException {
5+ public static void main (String [] args ) throws Exception {
6+
67 BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
78
89 StringTokenizer st = new StringTokenizer (br .readLine ());
910
1011 int N = Integer .parseInt (st .nextToken ());
11- int K = Integer .parseInt (st .nextToken ());
1212
13- Queue < Integer > queue = new LinkedList <>( );
13+ int K = Integer . parseInt ( st . nextToken () );
1414
15- for (int i =1 ; i <=N ; i ++) {
15+ Queue <Integer > queue = new LinkedList <>();
16+ StringBuilder sb = new StringBuilder ();
17+ sb .append ("<" );
18+ for (int i = 1 ;i <=N ; i ++) {
1619 queue .add (i );
1720 }
18- int index = 1 ;
19- ArrayList < Integer > list = new ArrayList <>();
20- while (!( queue .size () == 0 )) {
21-
22- if (index ! = K ) {
23- int cur = queue .poll ();
24- queue . add ( cur );
25- index ++;
26- }
27- else if ( index == K ) {
28- int cur = queue . poll () ;
29- list . add ( cur );
30- index = 1 ;
21+ int index = 0 ;
22+ while (! queue . isEmpty ()) {
23+ int temp = queue .poll ();
24+ index += 1 ;
25+ if (index = = K ) {
26+ if (! queue .isEmpty ()) {
27+ sb . append ( temp ). append ( ", " );
28+ } else {
29+ sb . append ( temp );
30+ }
31+ index = 0 ;
32+ } else {
33+ queue . add ( temp ) ;
3134 }
35+
3236 }
33- System .out .print ("<" );
3437
35- for (int i =0 ; i <N -1 ; i ++) {
36- System .out .print (list .get (i )+", " );
37- }
38- System .out .print (list .get (N -1 ));
39- System .out .print (">" );
38+ sb .append (">" );
39+
40+ System .out .println (sb );
4041 }
41- }
42+ }
You can’t perform that action at this time.
0 commit comments