CSU 2018年12月月赛 D 2216 : Words Transformation
Description
There are n words, you have to turn them into plural form.
If a singular noun ends with ch, x, s, o, then the plural is -es. For example, witch -> witches, tomato -> tomatoes.
If a singular noun ends with f or fe, then the plural is -ves. For example, leaf -> leaves, knife -> knives. Note that f becomes v.
The noun ending with y will become -ies. For example, family -> families.
All other singular nouns are added with s. For example, book -> books.
Input
The first line, a number n, represents the number of words.
Next n lines, each line represents a word.
The number of words <= 10000, 1 <= word length <= 100.
Output
N lines.
Output the words in plural form.
Sample Input
3
contest
hero
lady
Sample Output
contests heroes ladies
题意:模拟题,水题,注意f,fe这块就行了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
const int maxn=10005;
int n;
string s;
int main()
{
scanf("%d",&n);
while(n--)
{
cin>>s;
int len=s.length();
if(s[len-1]=='x'||s[len-1]=='s'||s[len-1]=='o'||(s[len-1]=='h'&&s[len-2]=='c'))
{
cout<<s<<"es"<<endl;
}
else if(s[len-1]=='y')
{
for(int i=0;i<len-1;i++)
cout<<s[i];
cout<<"ies"<<endl;
}
else if(s[len-1]=='f')
{
for(int i=0;i<len-1;i++)
cout<<s[i];
cout<<"ves"<<endl;
}
else if((s[len-1]=='e'&&s[len-2]=='f'))
{
for(int i=0;i<len-2;i++)
cout<<s[i];
cout<<"ves"<<endl;
}
else
cout<<s<<"s"<<endl;
}
return 0;
}
/**********************************************************************
Problem: 2216
User: therang
Language: C++
Result: AC
Time:420 ms
Memory:2024 kb
**********************************************************************/