ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 10813 JAVA
    ETC/Algorithm 2023. 5. 19. 23:15
    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;
    
                temp = bucket[i];
                bucket[i] = bucket[j];
                bucket[j] = temp;
            }
            for (int number : bucket) {
                bw.write(number + " ");
            }
            bw.flush();
        }
    }

    댓글

Designed by black7375.