๋ฐ์ํ
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 ์๊ณ ๋ฆฌ์ฆ ์๋ฐํธ์ ๋ค์ ๋ด์ผํ๋ ์ถ๋ค์.
์๊ณ ๋ฆฌ์ฆ์ ๋จ์ํ ํธ๋ ๊ฒ ์ค์ํ ๊ฒ ์๋๋ผ ์ด๋ป๊ฒ ์งฐ๋ ์ง๊ฐ ์ค์ํ๋๋ผ๊ตฌ์.
๋ฐ์ํ
'๐ธ Algorithm > ๐ธ ๋ฐฑ์ค BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][java][10811][๋ฐ๊ตฌ๋ ๋ค์ง๊ธฐ] (0) | 2023.11.12 |
---|---|
[๋ฐฑ์ค][java][5597][๊ณผ์ ์ ๋ด์ ๋ถ..?] (0) | 2023.11.12 |
[๋ฐฑ์ค][java][10810][๊ณต ๋ฃ๊ธฐ] (1) | 2023.10.22 |
[๋ฐฑ์ค][java][2562][์ต๋๊ฐ] (0) | 2023.10.15 |
[๋ฐฑ์ค][java][10818][์ต์, ์ต๋] (0) | 2023.10.15 |