UVA101求助
  • 板块题目总版
  • 楼主Zhang_enze
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/4 22:04
  • 上次更新2024/8/5 08:29:25
查看原帖
UVA101求助
1415235
Zhang_enze楼主2024/8/4 22:04
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h, z, hb, zb;
string s1, s2;
vector<int> t[50];
void find1(int x) {
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < t[i].size(); j ++) {
			if (t[i][j] == x) {
				h = i, z = j;
			}
		}
	}
}
void guiwei(int x1, int x2) {
	for (int i = x2 + 1; i < t[x1].size(); i ++) {
		int tmp = t[x1][i];
		t[tmp].push_back(tmp);
	}
}
void tuo(int x1, int x2) {
	for (int i = z; i < t[h].size(); i ++) {
		t[hb].push_back(t[h][i]);
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) {
		t[i].push_back(i);
	}
	while (1) {
		cin >> s1;
		if (s1 == "quit") break;
		cin >> a >> s2 >> b;
		find1(a);
		int h1 = h;
		find1(b);
		if (h1 == h) continue;
		if (s1 == "move" && s2 == "onto") {
			find1(a);
			guiwei(h, z);
			t[h].resize(z);
			find1(b);
			guiwei(h, z);
			t[h].resize(z + 1);
			t[h].push_back(a);
		}
		if (s1 == "move" && s2 == "over") {
			find1(a);
			guiwei(h, z);
			t[h].resize(z);
			find1(b);
			t[h].push_back(a);
		}
		if (s1 == "pile" && s2 == "onto") {
			find1(b);
			hb = h, zb = b;
			guiwei(h, z);
			t[h].resize(z + 1);
			find1(a);
			tuo(hb, zb);
			t[h].resize(z);
		}
		if (s1 == "pile" && s2 == "over") {
			find1(b);
			hb = h, zb = b;
			find1(a);
			tuo(hb, zb);
			t[h].resize(z);
		}
	/*	for (int i = 0; i < n; i ++) {
			for (int j = 0; j < t[i].size(); j ++) {
				cout << t[i][j] << ' ';
			}
			cout << endl;
		}*/
	}
	for (int i = 0; i < n; i ++) {
		cout << i << ": ";
		for (int j = 0; j < t[i].size(); j ++) {
			cout << t[i][j] << ' ';
		}
		cout << endl;
	} 
	return 0;
}

样例过了,但是WA0分 求助各位大佬纠错

2024/8/4 22:04
加载中...