[HDOJ]problem_1075【What Are You Talking About】:
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
map<string,string> str;
map<string,string> ::iterator pos;
int i,j,n,t,r,k;
char s1[30],s2[30],s3[3005];
while (scanf("%s",s1)&&strcmp(s1,"START")!=0);
while (scanf("%s",s1)&&strcmp(s1,"END")!=0)
{
scanf("%s",s2);
str[s2]=s1;
}
while (scanf("%s",s1))
{
if (strcmp(s1,"START")==0)
break;
}
getchar(); //******
while (gets(s3))
{
if (strcmp(s3,"END")==0)
return 0;
r=0;
for (i=0;i<strlen(s3);i++)
{
if (s3[i]>='a'&&s3[i]<='z')
{
s1[r++]=s3[i];
}
else
{
s1[r]='\0';
r=0;
if (str.find(s1)!=str.end())
cout<<str[s1];
else
cout<<s1;
printf("%c",s3[i]);
}
}
printf("\n");
}
return 0;
}
刚开始没有加getchar();第二个START后面会有个空行,一直不明白为什么。后来问了学长才知道原来回车只是作为%s结束的标志,后面的gets(str3);会把回车吃掉。哈哈……还真是一个细小的问题,虽然细小,还是值得注意的