๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][10813][๊ณต ๋ฐ”๊พธ๊ธฐ]

๋‰ด์ด NUEY 2023. 11. 5. 21:01
๋ฐ˜์‘ํ˜•

import java.util.Scanner;

public class Main {
	// 10813	๊ณต ๋ฐ”๊พธ๊ธฐ
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] ball = new int[sc.nextInt()];
		int m = sc.nextInt();
		
		for (int i = 1; i <= ball.length; i++) {
			ball[i-1] = i;
		}
		
		for (int j = 0; j < m; j++) {
			int firstIn = sc.nextInt();
			int secondIn = sc.nextInt();
			int firstBall = ball[firstIn-1];
			int secondBall = ball[secondIn-1];
			
			ball[firstIn-1] = secondBall;
			ball[secondIn-1] = firstBall;
		}
		
		for (int i = 0; i < ball.length; i++) {
			System.out.printf("%d ", ball[i]);
		}
	}
}

 

 

์‚ฌ๋‹ด

๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€๊ธด ํ–ˆ๋Š”๋ฐ ๋งˆ์Œ์— ๋“ค๊ฒŒ ๊น”๋”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค..
์Šฌ์Šฌ ์ „์— ์‚ฌ๋‘๊ณ  ๋ณด๋‹ค ๋งŒ Do it ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”ํŽธ์„ ๋‹ค์‹œ ๋ด์•ผํ•˜๋‚˜ ์‹ถ๋„ค์š”.
์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹จ์ˆœํžˆ ํ‘ธ๋Š” ๊ฒŒ ์ค‘์š”ํ•œ ๊ฒŒ ์•„๋‹ˆ๋ผ ์–ด๋–ป๊ฒŒ ์งฐ๋Š” ์ง€๊ฐ€ ์ค‘์š”ํ•˜๋”๋ผ๊ตฌ์š”.

 

๋ฐ˜์‘ํ˜•