STL-E The Blocks Problem (UVA - 101)
2018-02-13 20:20
405 查看
#include <cstdio> #include <string> #include <vector> #include <iostream> #include <string.h> using namespace std; const int maxn = 30; int n; vector <int> block[maxn]; int found(int a ) { int i , h; for (i=0;i <n;i++) for (h=0;h<block[i].size();h++) { if (block[i][h] == a) { return i*100+h; } } } void release (int x1,int x2) { int i; for (i=x2+1;i<block[x1].size();i++)//下标比实际少了1 { block[block[x1][i]].push_back(block[x1][i]);//放回原处 } block[x1].resize(x2+1); } int main() { int a,b,num1,num2,x1,x2,x3,x4,i; scanf("%d",&n); char s1[5],s2[5]; for (i =0;i<n;i++) block[i].push_back(i);//给每个方块上添加一个对应的数 while (~scanf("%s %d %s %d",s1,&a,s2,&b)&&s1!="quit") { num1=found(a); x1 = num1/100; x2 = num1%100;//查找a 和 num2=found(b); x3 = num2/100; x4 = num2%100;//b 的位置 if (x1 == x3) continue; if (strcmp(s1,"move")==0) { release(x1,x2); if (strcmp(s2,"onto")==0) { release(x3,x4); block[x3].push_back(block[x1][x2]); block[x1].resize(x2); } else { block[x3].push_back(block[x1][x2]); block[x1].resize(x2); } } else if (strcmp(s1,"pile")==0) { if (strcmp(s2,"onto")==0) { release(x3,x4); } for(i = x2; i < block[x1].size(); i++) block[x3].push_back(block[x1][i]); block[x1].resize(x2); } } for(int i=0;i<n;i++) { printf("%d:",i); for(int j=0;j<block[i].size();j++) { printf(" %d",block[i][j]); } printf("\n"); } return 0; }
相关文章推荐
- UVa 101 The Blocks Problem 【STL】【vector】【模拟】
- UVa 101 - The Blocks Problem(STL)
- 例题5-2 UVa101 The Blocks Problem(STL:vector)
- UVA - 101 The Blocks Problem(STL,模拟)
- UVa101-The Blocks Problem/STL-Vector的使用
- Uva 101 The Blocks Problem(不定长数组 vector)
- uva101 - The Blocks Problem
- UVA 101 The Blocks Problem
- UVa 101 The Blocks Problem
- 数据结构 uva 101 - The Blocks Problem
- UVa 101 The Blocks Problem
- UVa 101 (模拟) The Blocks Problem
- UVA101 The Blocks Problem(模拟)
- UVA 101(p110)----The Blocks Problem
- UVA - 101 The Blocks Problem
- UVa系列——101/The Blocks Problem
- UVA-101 The Blocks Problem 栈模拟
- UVa 101 - The Blocks Problem
- UVA - 101 The Blocks Problem
- Uva-101-The Blocks Problem