写个大模拟都T了哪位大佬帮下我
查看原帖
写个大模拟都T了哪位大佬帮下我
483058
陈泽涵爱g编程楼主2023/11/2 23:05
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
int  n;
struct e {
	string ty, a;
	int begin, end;//在struct中的相对结束和相对开始位置位置
};
struct node {
	int almax, len;
	vector<e>v;
};
map<string, int> bsty;
map<string, node>ty;
//ty[string].v[i]其中的
vector<e>C_nint;
void op1() {
	string s;
	int k, ans = 0;
	cin >> s >> k;
	vector<string> g;
	vector<string>tye;
	for(int i = 1; i <= k; i++) {
		string t, num;
		cin >> t >> num;
		if(bsty.find(t) != bsty.end()) {
			ans = max(ans, bsty[t]);
		} else {
			ans = max(ans, ty[t].almax);
		}
		g.push_back(num);
		tye.push_back(t);
	}
	vector<e>pp;
	int cnt = -1;
	for(int i = 0; i < k; i++) {
		string t = tye[i], a = g[i];
//		cout << "debug : t " << t << '\n' ;
		int begin = cnt + 1;
		if(bsty.find(t) != bsty.end()) {
			cnt += ans;
		} else {
			cnt += ty[t].len;
		}
		pp.push_back({t, a, begin, cnt});
	}
	ty[s] = {ans, cnt + 1, pp};
	cout << cnt + 1 << ' ' << ans << '\n';
	return  ;
}
int C_nt = -1;
void op2() {
	string t, a;
	cin >> t >> a;
	cout << C_nt + 1 << '\n';
	int begin = C_nt + 1;
	if(bsty.find(t) != bsty.end()) {
		C_nt += bsty[t];
	} else {
		C_nt += ty[t].len;
	}
	C_nint.push_back({t, a, begin, C_nt});
}
void op3() {
	string s;
	cin >> s;
	int it = 0;
	string str = "";
	int len = s.size();
	int beg;
	while(s[it] != '.') {
		str += s[it];
		it++;
	}
	for(int i = 0; i < C_nint.size(); i++) {
		if(str == C_nint[i].a) {
			beg = C_nint[i].begin;
			str = C_nint[i].ty;
			break;
		}
	}
	string fstr = "";
	while(it < len) {
		fstr = "";
		while(s[it] != '.' && it < len) {
			fstr += s[it];
			it++;
		}
//		cout << str << ' ' << ty[str].v.size() << '\n';
		for(int i = 0; i < ty[str].v.size(); i++) {

			if(fstr == ty[str].v[i].a) {
//				cout << ty[str].v[i].a << " " << ty[str].v[i].begin << "\n";
				beg +=ty[str].v[i].begin;
				str = ty[str].v[i].ty;
				break;
			}
		}
		it++;
	}
	cout <<beg << '\n';
	return ;
}
void op4() {
	int addr;
	cin >> addr;
	string str, a;
	int beg;
	for(int i = 0; i < C_nint.size(); i++) {
		if(addr <= C_nint[i].end) {
			beg = C_nint[i].begin;
			str = C_nint[i].ty;
			a = C_nint[i].a;
			break;
		}
	}
	if(bsty.find(str) != bsty.end()) {
		cout << a << '\n';
		return ;
	}
	cout << a;
	while(1) {
		for(int i = 0; i < ty[str].v.size(); i++) {
			int begin = beg + ty[str].v[i].begin, end = beg + ty[str].v[i].end;
			if(begin <= addr && end >= addr) {
//				cout << 1;
				beg = begin;
				a = ty[str].v[i].a;
				str = ty[str].v[i].ty;
				break;
			}
		}
		cout << ".";
		if(bsty.find(str) != bsty.end()) {
			cout << a << '\n';
			return ;
		}
		cout << a;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	bsty["byte"] = 1;
	bsty["short"] = 2;
	bsty["int"] = 4;
	bsty["long"] = 8;
	for(int i = 1; i <= n; i++) {
		int opt;
		cin >> opt;
		if(opt == 1) {
			op1();
		}
		if(opt == 2) {
			op2();
		}
		if(opt == 3) {
			op3();
		}
		if(opt == 4) {
			op4();
		}
	}
	return 0;
}
/*
3
1 a 2
short aa
int ab
1 b 2
a ba
long bb
2 b x
*/
2023/11/2 23:05
加载中...