백준 10813 c++

magicdrill·2024년 3월 26일
0

백준 문제풀이

목록 보기
212/654

백준 10813 c++

#include <iostream>
using namespace std;
int main(void)
{
	int N, M;
	int* arr = NULL;
	int i, j;
	int s;
	int temp;

	cin >> N >> M;
	if ((N>=1 && N <=100) && (M >= 1 && M <= 100))
	{
		arr = new int[N];
		for (s = 0; s < N; s++)
		{
			arr[s] = s + 1;
		}
		for (s = 0; s < M; s++)
		{
			cin >> i >> j;
			if ((i >= 1 && i <= j) && (j >= 1 && j <= N))
			{
				temp = arr[i - 1];
				arr[i - 1] = arr[j - 1];
				arr[j - 1] = temp;
			}
			else
			{
				s--;
			}
		}
		for (s = 0; s < N; s++)
		{
			cout << arr[s] << " ";
		}
		cout << endl;
	}
	else
	{
		;
	}

	delete[] arr;

	return 0;
}

0개의 댓글