ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 10811 JAVA
    ETC/Algorithm 2023. 5. 19. 23:14
    import java.io.*;
    import java.util.StringTokenizer;
    
    public class Main {
        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 st;
    
            st = new StringTokenizer(br.readLine(), " ");
    
            int n = Integer.parseInt(st.nextToken());
            int m = Integer.parseInt(st.nextToken());
    
            int[] bucket = new int[n];
            for (int k = 0; k < n; k++) {
                bucket[k] = k + 1;
            }
    
            int temp;
    
            for (int k = 0; k < m; k++) {
                st = new StringTokenizer(br.readLine(), " ");
    
                int i = Integer.parseInt(st.nextToken()) - 1;
                int j = Integer.parseInt(st.nextToken()) - 1;
    
                for (int l = i, t = j; l < t; l++, t--) {
                    temp = bucket[l];
                    bucket[l] = bucket[t];
                    bucket[t] = temp;
                }
    
            }
            for (int number : bucket) {
                bw.write(number + " ");
            }
            bw.flush();
        }
    }

    memo.

    ArrayList 의 subList를 사용했을 떄
    subList의 값이 변경되면 원본의 값이 변경 된다는데,
    이 점을 사용하면 뭔가 더 가능하지 않을까?

    댓글

Designed by black7375.