用map超内存,暴力写
MLE
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
map<string,string>m1;
map<string,string>m2;
map<string,string>::iterator it;
string s1,s2;
string s;
int main()
{
while(cin>>s1&&s1[0]!='@')
{
getchar();
getline(cin,s2);
m1[s1]=s2;
m2[s2]=s1;
}
int n;
cin>>n;
getchar();
while(n--)
{
getline(cin,s1);
if((it=m1.find(s1))!=m1.end())
{
cout<<it->second<<endl;
continue;
}
if((it=m2.find(s1))!=m2.end())
{
cout<<it->second<<endl;
continue;
}
cout<<"what?"<<endl;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
struct spell
{
char a[30],b[100];
} s[100005];
char s1[30],s11[30],s2[100];
char ss[100];
int main()
{
int i=0;
while(scanf("%s",s1)!=-1&&s1[0]!='@')
{
getchar();
gets(s2);
strcpy(s[i].a,s1);
strcpy(s[i++].b,s2);
}
int t;
scanf("%d",&t);
getchar();
while(t--)
{
gets(ss);
int flag=0;
for(int k=0; k<i; k++)
{
if(strcmp(ss,s[k].a)==0)
{
printf("%s\n",s[k].b);
flag=1;
}
else if(strcmp(ss,s[k].b)==0)
{
int len=strlen(s[k].a);
for(int j=1; j<len-1; j++)
s11[j-1]=s[k].a[j];
printf("%s\n",s11);
flag=1;
}
}
if(flag==0)
printf("what?\n");
}
return 0;
}