UVAThe blocks problem VECTOR的使用
2015-02-16 16:20
211 查看
#include<iostream> #include<string> #include<cstdio> #include<vector> using namespace std; const int maxn = 30; int n; vector<int> pile[maxn]; void find_block(int x, int& p, int& h){ for(p=0; p < n;p++) for(h=0; h < pile[p].size();h++) if(x == pile[p][h]) return; } void move_above(int p, int h){ for(int i=h+1; i < pile[p].size();i++) { int b = pile[p][i]; pile[b].push_back(b); } pile[p].resize(h+1); } void pile_onto(int p, int h, int p2){ for(int i = h; i < pile[p].size();i++) pile[p2].push_back(pile[p][i]); pile[p].resize(h); } int main() { cin >> n; int a,b; string s1,s2; for(int i = 0; i<n;i++) pile[i].push_back(i); while(cin >> s1 >> a >> s2 >> b){ int pa, pb, ha, hb; find_block(a, pa, ha); find_block(b, pb, hb); if(pa == pb) continue; if(s1 == "move") move_above(pa, ha); if(s2 == "onto") move_above(pb, hb); pile_onto(pa, ha, pb); } for(int i=0; i < n; i++) { printf("%d:",i); for(int j=0; j < pile[i].size(); j++) printf(" %d", pile[i][j]); printf("\n"); } return 0; }
相关文章推荐
- UVa101-The Blocks Problem/STL-Vector的使用
- 经典第五章例5.2 UVA 101 The Blocks Problem(vector的基础应用)
- poj 1208 The Blocks Problem 模拟+vector的使用
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
- 例题5-2 UVa101 The Blocks Problem(STL:vector)
- UVa_The Blocks Problem(Vector)
- Problem B The Blocks Problem(vector的使用)
- UVa 101 The Blocks Problem Vector基本操作
- UVA 101 The Blocks Problem【vector】
- Uva 101 The Blocks Problem(不定长数组 vector)
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
- C++ 不定长数组vector 例5-2木块问题(The Blocks Problem,UVa 101)
- UVa 101 The Blocks Problem 【STL】【vector】【模拟】
- UVa 101 The Blocks Problem(vector)
- UVa 101 The Blocks Problem Vector基本操作
- UVA 101 The Blocks Problem【vector】
- UVa Problem 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- uva101 The Blocks Problem