Hdu 1075 What Are You Talking About

大意略。

思路:练习练习map的使用,代码丑了点,但总算AC了, - -!~

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
using namespace std;

map<string, string> Map;

char s1[15], s2[15];
char ans[50010];

void solve()
{
	while(scanf("%s", s1) && strcmp(s1, "END"))
	{
		scanf("%s", s2);
		Map[s2] = s1;
	}
	scanf("%s%*c", s1);
	while(gets(ans) && strcmp(ans, "END"))
	{
		int len = strlen(ans);
		char save[20];
		for(int i = 0, tot = 0; i < len; i++)
		{
			if(isalpha(ans[i]))
			{
				save[tot++] = ans[i];
			}
			else
			{
				save[tot] = '\0';
				if(Map.find(save) != Map.end()) cout<<Map[save];
				else printf("%s", save);
				printf("%c", ans[i]);
				tot = 0;
			}
		}
		printf("\n");
	}
}

int main()
{
	while(~scanf("%s", s1))
	{
		solve();
	}
	return 0;
}


你可能感兴趣的:(Hdu 1075 What Are You Talking About)