题目1029:魔咒词典

#include 
#include 
#include 
#include 
#include 

const int N = 200;

using namespace std;

char buf[N];

int main()
{
	string s;
	map m;
	int n;

#ifndef ONLINE_JUDGE
	freopen("e:\\uva_in.txt", "r", stdin);
#endif

	while (gets(buf))
	{
		if (strcmp(buf, "@END@") == 0)
			break;

		s = buf;
		int pos = s.find("]");
		string temp = s.substr(0, pos + 1);

		m.insert(make_pair(temp, s.substr(pos + 2)));

	}

	scanf("%d", &n);
	getchar();
	while (n--) {
		gets(buf);
		s = buf;
		map::iterator it = m.find(s);

		if (it != m.end()) {
			printf("%s\n", it->second.c_str());
		} else {
			for (it = m.begin(); it != m.end(); it++) {
				if (it->second == s) {
					string temp = it->first;
					temp = temp.substr(1, temp.length() - 2);
					printf("%s\n", temp.c_str());
					break;
				}
			}
			if (it == m.end())
				printf("what?\n");
		}
	}
	return 0;
}

你可能感兴趣的:(#,九度)