HDU 1075 What Are You Talking About

用map做的,

#include <iostream>
#include <map>
#include <string>
#include <cctype>
using namespace std;
map<string ,string> m;
int main()
{
	string mar,earth,s;
	cin>>s;
	while(cin>>earth)
	{
		if(earth=="END")
			break;
		cin>>mar;
		m[mar]=earth;
	}
	getchar();
	string str,code;
	int i,j;
	while(getline(cin,str))
	{
		code="";
		if(str=="END") break;
		if(str=="START") continue;
		for(i=0;i<str.size();i++)
		{
			
			if(isalpha(str[i]))
			{
				code+=str[i];
				if(!isalpha(str[i+1]))
				{
					if(m[code]!="")
						cout<<m[code];
					else
						cout<<code;
					code="";
				}
				
			}
			else
				cout<<str[i];
		}
		cout<<endl;
	}
	return 0;
}


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章