题意:样例输入
START
love abc
you dddd
END
START
i abc dddd!
END
样例输出
i love you!
注意:文本如果输入
细节问题
使用STL的MAP
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<cstring>
using namespace std;
map<string, string>str;
char ss[20000];
char ssr[20000];
char c[20000];
int main()
{
string a, b;
while (cin >> a)
{
if (a == "START")
{
break;
}
}
while (cin >> a)
{
if (a == "END")
{
break;
}
cin >> b;
str[b] = a;//map
}
while (cin >> a)
{
if (a == "START")
{
break;
}
}
getchar();
char *cc = "END";
cin.getline(ss,15000,*cc);
strcpy(ssr, ss);
int i = strlen(ssr);
for (int j = 0; j < i; j++)//变ss,ssr保持不变,把ss中的非字母变为空格
{
if (!isalpha(ss[j]))
{
ss[j] =' ';
}
}
for (int j = 0; j < i; j++)
{
if (ss[j] ==' ')//如果为空格,输出原来的字符
{
cout << ssr[j];
}
else
{
for (int k = 0;; k++, j++)
{
if (ss[j] ==' ')
{
j--;
a = c;
if (str.find(a) != str.end())//map中存在
{
cout << str[a];
}
else//不存在的话;
{
cout << a;
}
c[k] = '\n';
memset(c, 0, sizeof(c));
break;
}
c[k] = ss[j];
}
}
}
return 0;
}
网友评论