View Code of Problem 1063

/*
用栈直接模拟
非常方便! 
*/
#define LOCAL
#include<iostream>
#include<stack>
using namespace std;
int main()
{
#ifdef LOCAL
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
#endif
    
    
    int n,r,p,q,i;
    while(cin>>n>>r,n)
    {
         stack<int> a,b,c;
         for(i=1;i<=n;i++)
              a.push(i);
         while(r--)
         {
                cin>>p>>q;
                p--;
                while(p--)
                {
                      b.push(a.top());
                      a.pop();          
                }
                while(q--)
                {
                      c.push(a.top());
                      a.pop();          
                }          
                while(!b.empty())
                {
                      a.push(b.top());
                      b.pop();           
                }
                while(!c.empty())
                {
                      a.push(c.top());
                      c.pop();           
                }
         }
         cout<<a.top()<<endl;
                     
    }
    return 0;
}

/*
F:\temp\16139736.54753\Main.cc: In function 'int main()':
F:\temp\16139736.54753\Main.cc:13: error: 'stdin' was not declared in this scope
F:\temp\16139736.54753\Main.cc:13: error: 'freopen' was not declared in this scope
F:\temp\16139736.54753\Main.cc:14: error: 'stdout' was not declared in this scope
*/

Double click to view unformatted code.


Back to problem 1063