STL 的map容器使用
题意:给你一些单词的对应表,然后给你一些句子,输出句子,并把句子中与单词对应表中相对应的单词输出
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<string,string> mp;
int main()
{
string s1,s2;
map<string,string>::iterator iter;
char ch;
while(cin>>s1)
{
mp.clear();
while(true)
{
cin>>s1;
if(s1=="END")break;
cin>>s2;
mp[s2]=s1;
}
cin>>s1;
getchar();
while(true)
{
s2="";
while(scanf("%c",&ch)!=EOF)
{
if(ch=='\n'&&s2=="END") return 0;
if(ch=='\n') break;
if(!isalpha(ch))
{
iter=mp.find(s2);
if(iter!=mp.end())cout<<iter->second;
else
cout<<s2;
cout<<ch;
s2="";
}
else s2+=ch;
}
printf("\n");
}
}
return 0;
}