티스토리 뷰
마지막 문제는 달달해서 감사합니다...
그냥 배열 12345... 로 초기화하고 temp를 이용해 Swap해주면 되는 문제다.
BufferedStream bs = new BufferedStream(Console.OpenStandardInput()); StreamReader sr = new StreamReader(bs); StringBuilder sb = new StringBuilder(); string[] nm = Console.ReadLine().Split(); int[] basket = new int[int.Parse(nm[0]) + 1]; for (int i = 1; i < basket.Length; i++) basket[i] = i; int cnt = int.Parse(nm[1]); int temp; while (cnt-- > 0) { nm = Console.ReadLine().Split(); temp = basket[int.Parse(nm[0])]; basket[int.Parse(nm[0])] = basket[int.Parse(nm[1])]; basket[int.Parse(nm[1])] = temp; } for (int i = 1; i < basket.Length; i++) sb.Append(basket[i] + " "); Console.WriteLine(sb);
'■ 알고리즘 > ◻ 백준' 카테고리의 다른 글
알고리즘 기초 문제 풀이 순서 (0) | 2022.07.20 |
---|---|
[C#]백준 2750번 : 수 정렬하기 (0) | 2018.08.14 |
[C#]백준 10812번 : 바구니 순서 바꾸기 (0) | 2018.08.14 |
[C#]백준 10811번 : 바구니 뒤집기 (0) | 2018.08.14 |
[C#]백준 10810번 : 공 넣기 (0) | 2018.08.14 |