关于大样例没过却AC了
查看原帖
关于大样例没过却AC了
332914
happybob楼主2022/4/17 17:18
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstring>
#include <string>
using namespace std;

int n;
unordered_map<string, string> mp;
unordered_map<string, bool> f;

inline string change(string ss)
{
	string s = ss, p = "", ans = "";
	s += " ";
	int len(s.size() - 1);
	for (int i = 0; i <= len; i++)
	{
		if (!isalpha(s[i]) && !isdigit(s[i]) && s[i] != '_')
		{
			if (mp.count(p) && !f.count(p))
			{
				f[p] = true;
				ans += change(mp[p]);
				f.erase(p);
			}
			else
			{
				ans += p;
			}
			ans += s[i];
			p = "";
			f.clear();
		}
		else
		{
			p += s[i];
		}
	}
	ans.erase(--ans.end());
	return ans;
}

int main()
{
	cin >> n;
	getchar();
	for (int i = 1; i <= n; ++i)
	{
		string s;
		getline(cin, s);
		int len = s.size() - 1;
		if (s[0] == '#')
		{
			if (s[1] == 'd') // 如果是宏定义
			{
				/*
				* e: 2
				* f: 3
				* i: 4
				* n: 5
				* e: 6
				*/
				string s1 = "", s2 = "";
				for (int j = 8; j <= len; j++)
				{
					if (s[j] == ' ')
					{
						s2 = s.substr(j + 1, len - j);
						break;
					}
					s1 += s[j];
				}
				mp[s1] = s2;
			}
			else
			{
				/*
				* u: 1
				* n: 2
				* d: 3
				* e: 4
				* f: 5
				*/
				string s1 = s.substr(7, len - 6);
				mp.erase(s1);
			}
			puts("");
		}
		else
		{
			cout << change(s) << "\n";
		}
	}
	return 0;
}

dev-c++ TDM-GCC 10.3.0: -std=c++14 -O2,样例 33 没过却 AC 了,并且在洛谷IDE貌似得到了不同的信息,这是怎么回事?

2022/4/17 17:18
加载中...