1#include <iostream>2#include <string>3#include <vector>4#include <cstdio>5 using namespacestd;6 intN;7vector<int> pile[ -];8 9 //find the pile and height of a where the caller is returned as an application,Ten voidFind_block (intAint&p,int&h) One { A for(p=0;p <n;p++) - for(h=0; H<pile[p].size (); h++) - if(pile[p][h]==a) the return ; - } - - voidClear_above (intPinth) + { - for(inti=h+1; I<pile[p].size (); i++) + { A intb=Pile[p][i]; at Pile[b].push_back (b); - } -Pile[p].resize (H +1); - } - voidPile_onto (intPintHintp2) - { in for(intI=h;i<pile[p].size (); i++) The capacity size of the//pile[p].size () - Pile[p2].push_back (Pile[p][i]); to pile[p].resize (h);//pile[p] capacity changed to H size + } - voidprint () the { * for(intI=0; i<n;i++) $ {Panax Notoginsengprintf"%d:", i); - for(intj=0; J<pile[i].size (); j + +) theprintf"%d", Pile[i][j]); +printf"\ n"); A } the } + - $ intMain () $ { - intb; -scanf"%d",&n); the strings1,s2; - for(intI=0; i<n;i++) Wuyi Pile[i].push_back (i); the while(cin>>s1>>a>>s2>>b) - { Wu intPA,PB,HA,HB; - Find_block (a,pa,ha); About Find_block (B,PB,HB); $ if(pa==pb) - Continue; - if(s2=="onto") Clear_above (PB,HB); - if(s1=="Move") Clear_above (pa,ha); A Pile_onto (PA,HA,PB); + print (); the } - $ return 0; the}
Vector class:
Pile[p].size () See Capacity size
Pile[p].resize (n) resizing the vector container
Pile[p].empty () to determine if it is empty
Begin () and end () functions--Returns the position of the first element and the last element
The front () and back () functions return the first and last elements of a vector
Push_back (x) and Pop_back () finally insert an element in the vector and delete an element
Vectors can be the same as the array, using the following table to indicate
STL Sector applications