#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<vector<int> > pile;
int n,a,b;
void find_pos(int wood,int &p,int &h){
for(p=0;p<n;p++){
for(h=0;h<pile[p].size();h++){
if(pile[p][h] == wood)return;
}
}
}
void move_initial(int p,int h){
for(int j=h+1;j<pile[p].size();j++){
pile[pile[p][j]].push_back(pile[p][j]);
}
pile[p].resize(h+1);
}
void move(int p1,int h1,int p2){
for(int i=h1;i<pile[p1].size();i++){
pile[p2].push_back(pile[p1][i]);
}
pile[p1].resize(h1);
}
int main(){
cin>>n;
pile.resize(n);
for(int i=0;i<pile.size();i++){
pile[i].push_back(i);
}
string s1,s2;
while(cin>>s1 && s1 != "quit"){
cin>>a>>s2>>b;
int p1,h1,p2,h2;
find_pos(a,p1,h1);
find_pos(b,p2,h2);
if(p1 == p2)continue;
if(s1 == "move")move_initial(p1,h1);
if(s2 == "onto")move_initial(p2,h2);
move(p1,h1,p2);
}
for(int i=0;i<n;i++){
cout<<i<<":";
for(int j=0;j<pile[i].size();j++){
cout<<" "<<pile[i][j];
}
cout<<endl;
}
return 0;
}
101 The Blocks Problem
最新推荐文章于 2018-06-12 17:08:38 发布