← Back to List

10811번: 바구니 뒤집기 ↗

Solutions

C++14
361 B | 361 chars
#include <iostream>
#include <stack>
using namespace std;
int N,M,a,b,ar[110];
stack <int> st;
int main()
{
	cin>>N>>M;
	for(int x=1; x<=N; x++) ar[x]=x;
	for(int x=1; x<=M; x++)
	{
		cin>>a>>b;
		for(int x=a; x<=b; x++)
		{
			st.push(ar[x]);
		}
		for(int x=a; x<=b; x++)
		{
			ar[x]=st.top();
			st.pop();
		}
	}
	for(int x=1; x<=N; x++) cout<<ar[x]<<" ";
}