水题一枚。
题目大意:按照题目要求将所给单词转化为复数形式。
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
int main()
{
map<string, string>M;
map<char, int>S;
int l,n;
S['a'] = 1, S['e'] = 1;
S['i'] = 1, S['o'] = 1, S['u'] = 1;
string s[102];
string a, b;
while (cin >> l >> n)
{
M.clear();
while (l--)
{
cin >> a >> b;
M[a] = b;
}
for (int i = 0;i < n;i++)
{
cin >> s[i];
if (M.find(s[i]) != M.end()) s[i] = M[s[i]];
else
{
int len = s[i].length();
switch (s[i][len - 1])
{
case 'y': if (len > 1 && (S.find(s[i][len - 2])) == S.end()) s[i][len - 1] = 'i', s[i] += "es";
else s[i] += "s";break;
case 'o':
case 's':
case 'x':s[i] += "es";break;
case 'h': if (len > 1 && (s[i][len - 2] == 'c' || s[i][len - 2] == 's'))
s[i] += "es";
else s[i] += "s";break;
default:s[i] += "s";break;
}
}
}
for (int i = 0;i < n;i++) cout << s[i] << endl;
}
return 0;
}