题目链接:Click here~~
水水的字符串处理。主要练习下map的用法。
不过这道题,让我一下就想起了初中刚学英语的时候,各种怀念啊。
题意:
输出单词的复数形式。有些是特殊变换的,它事先给你。其他的按照规则变换。
解题思路:
特殊变换的用map存,其他的直接模拟。
#include <map>
#include <string>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
bool fuyin(char c)
{
return c-'a' && c-'e' && c-'i' && c-'o' && c-'u';
}
bool ES(char d,char c)
{
return c=='o' || c=='s' || c=='x' || (c=='h'&&(d=='c'||d=='s'));
}
int main()
{
int n,m,l;
char a[25],b[25];
string A,B;
map<string,string> M;
map<string,string>::iterator it;
while(~scanf("%d%d",&m,&n))
{
while(m--)
{
scanf("%s%s",a,b);
M[a] = b;
}
while(n--)
{
scanf("%s",a);
it = M.find(a);
if(it != M.end())
cout<< (*it).second <<endl;
else
{
l = strlen(a);
if(fuyin(a[l-2]) && a[l-1]=='y')
{
a[l-1]='i';
strcat(a,"es");
}
else if(ES(a[l-2],a[l-1]))
strcat(a,"es");
else
strcat(a,"s");
puts(a);
}
}
M.clear();
}
return 0;
}