uva 101 - The Blocks Problem
2013-06-11 16:43
399 查看
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int stk[30][30], len[30], n; int main() { while (cin >> n) { for(int i = 0; i < n; i++) { stk[i][0] = i; len[i] = 1; } char s1[10], s2[10]; int num1, num2; while(scanf("%s", s1) && strcmp(s1, "quit")!=0) { scanf("%d%s%d", &num1, s2, &num2); if(num1 == num2) continue; int num1_i, num1_j, num2_i, num2_j; for(int i = 0; i < n; i++) for(int j = 0; j < len[i]; j++) { if(num1 == stk[i][j]) { num1_i=i; num1_j=j; } else if(num2 ==stk[i][j]) { num2_i=i; num2_j=j; } } if(num1_i == num2_i) continue; if(strcmp(s1,"move") == 0) { if(strcmp(s2,"onto") == 0) { for(int i = num1_j + 1; i < len[num1_i]; i++) len[stk[num1_i][i]] = 1; for(int i = num2_j + 1; i< len[num2_i]; i++) len[stk[num2_i][i]] = 1; len[num1_i] = num1_j; stk[num2_i][num2_j + 1] = stk[num1_i][num1_j]; len[num2_i] = num2_j + 2; } else { for(int i = num1_j + 1; i < len[num1_i]; i++) len[stk[num1_i][i]] = 1; stk[num2_i][len[num2_i]++] = stk[num1_i][num1_j]; len[num1_i] = num1_j; } } else { if(strcmp(s2,"onto") == 0) { for(int i = num2_j + 1; i < len[num2_i]; i++) len[stk[num2_i][i]] = 1; len[num2_i] = num2_j + 1; for(int i = num1_j; i < len[num1_i]; i++) stk[num2_i][len[num2_i]++] = stk[num1_i][i]; len[num1_i] = num1_j; } else { for(int i = num1_j; i < len[num1_i]; i++) stk[num2_i][len[num2_i]++] = stk[num1_i][i]; len[num1_i] = num1_j; } } } for(int i = 0; i < n; i++) { printf("%d:", i); for(int j = 0; j < len[i]; j++) printf(" %d", stk[i][j]); cout << endl; } } return 0; }
相关文章推荐
- UVA 101 - The Blocks Problem(模拟)
- UVa 101 (模拟) The Blocks Problem
- Problem 028——Uva 101 - The Blocks Problem
- Uva - 101 - The Blocks Problem
- UVA - 101 The Blocks Problem(STL,模拟)
- 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
- UVA - 101 The Blocks Problem
- UVa-101 - The Blocks Problem
- UVa101-The Blocks Problem/STL-Vector的使用
- UVa 101 - The Blocks Problem
- uva 101 The Blocks Problem (基本算法-模拟)
- 《算法竞赛入门经典2ndEdition 》例题5-2 木块问题(The Blocks Problem, Uva101)
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem