90分测试点6本地正确提交错误
查看原帖
90分测试点6本地正确提交错误
347589
Zelotz楼主2022/5/3 16:24
#include <bits/stdc++.h>
using namespace std;
#define srand srand(time(NULL))
#define random(x) rand() % (x)
#define il inline
#define ptc putchar
#define reg register
#define mp make_pair
typedef __int128 LL;
typedef long long ll;
typedef pair<int, int> PII;
namespace cyyh {
	template <typename T>
	il void read(T &x) {
		x = 0; T f = 1; char ch;
		while (!isdigit(ch = getchar())) f -= (ch == '-') << 1;
		while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar(); x *= f;
	}
	template <typename T, typename ...L>
	il void read(T &x, L &...y) {read(x); read(y...);}
	template <typename T>
	il void write(T x) {
		if (x < 0) ptc('-'), x = -x;
		if (x > 9) write(x / 10);	
		ptc(x % 10 + '0');
	}
}
using namespace cyyh;
const int N = 1005;
int n, tot, nowj;
struct node {
	string a, b; bool flg, used; // flg标识是否还能用,used表示是否展开过(当前一小段) 
} p[N];
bool chk(char c) {return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));}

pair<string, int> solve(string a) {
	for (int j = 1; j <= tot; ++j) {
		if (!p[j].flg || p[j].used) continue;
		if (p[j].a == a) return p[j].used = 1, mp(p[j].b, j);	
	}
//	cout << "fuck" << endl;
	return mp(a, 0);
}
bool twl(string a) {
	for (int i = 0; i < a.length(); ++i) if (a[i] == ' ') return false;
	return true;
} 
string work(string a) {
	string b, c;
	bool Find = 0;
//	cout << "asdsfsdsdfdsfdds" << a[a.length()] << "fdss"<<endl;
	for (int i = 0; i < a.length() + 1; ++i) {
		if (a[i] == '_' || (a[i] >= '0' && a[i] <= '9') || chk(a[i])) b += a[i];
		else {
			pair<string, int> s = solve(b);
			b = s.first;
			if (s.second) b = work(b);
			c += b, b = "";
			p[s.second].used = 0;
			if (i < a.length()) c += a[i];
		}
	}
//	cout << endl << '?' << ' ' << c << endl;
	return c;
}
int main() {
//	freopen("6.in", "r", stdin);
//	freopen("ans.txt", "w", stdout);
//	freopen("preprocessor.in", "r", stdin);
//	freopen("preprocessor.out", "w", stdout);
//	cout << chk('a') << ' ' << chk('Z') << ' ' << chk('8') << endl;
//	注意:连续最长的字母数字下划线为标识符;宏定义的有效范围不是从头开始也不是全局 
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		string a, b, c;
		cin >> a;	
		if (a[0] == '#') {
			if (a == "#define") cin >> b, getchar(), getline(cin, c), p[++tot] = {b, c, 1, 0};
			else if (a == "#undef") {
				cin >> b;
				for (int j = 1; j <= tot; ++j) if (p[j].flg && p[j].a == b) p[j].flg = 0;
			}
			puts("");
//			cout << a << ' ' << b << ' '<< c << endl;
		}
		else {
			getline(cin, b);
			a = a + b;
//			while (a != "!") c = a, a = work(a);
			for (int i = 1; i <= tot; ++i) p[i].used = 0;
			cout << work(a) << endl;
		}
//		if (i == 3) {
//			for (int i = 1; i <= tot; ++i) cout << p[i].a << ' ' << p[i].b << ' ' << endl;
//		}
	}
	return 0;
}

测试点6答案貌似全是换行

2022/5/3 16:24
加载中...