UVA - 101 The Blocks Problem
2018-04-10 04:34
323 查看
题意:模拟堆砖块的过程。
vector的应用。
vector的应用。
#include <iostream> #include <cstdio> #include <cstring> #include <vector> using namespace std; vector<int> data[100]; int n; int fin(int a) { for(int i = 0; i < n ; i++) { for(int j = 0; j < data[i].size(); j++) if(data[i][j] == a) return i; } } int mov(int x,int a) { int flag = 0; int mark = 0; int s = data[x].size(); for(int i = 0; i < s; i++) { int y = data[x][i]; if(mark != 0 ) data[y].push_back(y); if(data[x][i] == a) {flag = i;mark = 1;} } for(int i = flag+1; i < s; i++) data[x].pop_back(); /* for(int i = 0; i < data[x].size(); i++) cout<<data[x][i]<<' '; cout<<endl;*/ } int main() { // freopen("D://in.txt","r",stdin); scanf("%d",&n); char s[5],m[5]; int a,b; for(int i = 0; i < n ; i++) data[i].push_back(i); while(scanf("%s",s)) { if(s[0] == 'q') break; scanf("%d%s%d",&a,m,&b); int x = fin(a) , y = fin(b); int flag = 0; for(int i = 0; i < data[x].size(); i++) if(data[x][i] == a) flag = i; if(x == y) continue; if(s[0] == 'm' && m[1] == 'n') { mov(x,a); mov(y,b); data[x].pop_back(); data[y].push_back(a); } else if(s[0] == 'm' && m[1] == 'v') { mov(x,a); data[x].pop_back(); data[y].push_back(a); } else if(s[0] == 'p' && m[1] == 'n') { mov(y,b); for(int i = flag; i < data[x].size(); i++) data[y].push_back(data[x][i]); int ss = data[x].size(); for(int i = flag ; i < ss; i++) data[x].pop_back(); } else { int ss = data[x].size(); for(int i = flag ;i < ss;i++) data[y].push_back(data[x][i]); for(int i = flag ; i < ss; i++) data[x].pop_back(); } } for(int i = 0; i < n ; i++) { printf("%d:",i); for(int j = 0; j < data[i].size(); j++) { j == data[i].size()-1?printf(" %d\n",data[i][j]):printf(" %d",data[i][j]); } if(data[i].size() == 0) printf("\n"); } return 0; }
相关文章推荐
- UVA 101 - The Blocks Problem
- UVA-101 The Blocks Problem
- uva101 The Blocks Problem
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
- Uva 101 - The Blocks Problem
- UVa OJ The Blocks Problem 木块问题 101
- UVa Problem 101 - The Blocks Problem
- UVA 101 The Blocks Problem【vector】
- 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
- UVa 101 - The Blocks Problem
- 紫薯e5-2 uva101 the blocks problem
- uva 101 - The Blocks Problem 练习代码控制能力的题目吧 ,思路转化为代码,实现自己的比较复杂的想法
- UVA - 101 The Blocks Problem
- UVA-101 The Blocks Problem
- UVA101 The Blocks Problem (数据结构模拟)