天天看點

CCF 學生排隊

水題

反複swap交換就好了

中文題意不解釋了

#include<iostream>
using namespace std;
int a[] ;
      int n ;
 void init(){
      for(int i =  ; i <= n ; i++){
        cout << a[i] << " " ;
     }
     cout << endl ;
 }
 void solve(int q , int y){
     int x ;
     for(int i =  ; i <= n ; i++) if(a[i] == q ){x = i ; break ;}
      if(y >  ){
        for(int i = x ; i < x + y ; i++){
            swap(a[i] , a[i+] ) ;

        }
      }
      else if(y < ){
        for(int i = x ; i > x + y ; i--){
            swap(a[i] , a[i-]) ;

        }
      }


  return ;
 }
int main() {

     cin >> n ;
     for(int i =  ; i <= n ; i++) a[i] = i ;
     int m ;
     cin >> m ;
     int x , y ;
     for(int i =  ; i < m ; i++){
        cin >>x >> y ;
       solve(x , y ) ;
     //  init() ;
     }
      init() ;
     cout << endl ;
     return  ;
   }
           

繼續閱讀