#include <iostream>
#include <cstring>
#include <ctype.h>
using namespace std;
bool isVowel(char ch)
{
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': return true;
default:
return false;
}
}
void RegularPluralForm(char word[])
{
char PluralForm[81];
//1. 将字符串前后的空格去掉
//先定位第一个非空字符的位置
int i=0;
while(isspace(word[i]))
i++; // 得到第一个非空字符的位置
int AlphPos=i;
i=0;
//移除前面的空白字符
while(word[AlphPos]!='\0' && !isspace(word[AlphPos]))
{
word[i]=word[AlphPos];
i++;
AlphPos++;
}
word[i]='\0';
strcpy(PluralForm, word);
//2. 求单词字符串长度
int len;
i=0;
while(word[i]!='\0')
i++;
len = i;
//3. 对单词变换
int flag = 0;
// flag 为 0 表示仅需要加's'的情况。
//规则外的例外情况设置flag为1,其他情况分别设置flag为不同的值
//首先检查例外情况,优先处理
if(!strcmp(word, "quiz")||!strcmp(word, "swiz") ||!strcmp(word, "whiz"))
{
flag=1;
PluralForm[len]='z';
PluralForm[len+1]='e';
PluralForm[len+2]='s';
PluralForm[len+3]='\0';
}
// 对符合规则的非例外情况处理
if(flag!=1){
//(1)判断单词是否以s, x, z 结尾,或以ch或sh结尾,单词后加es;
if((word[len-1]=='s'|| word[len-1]=='x'|| word[len-1]=='z')||((word[len-2]=='c'||word[len-2]=='s') && word[len-1]=='h' ))
{
flag=2;
PluralForm[len]='e';
PluralForm[len+1]='s';
PluralForm[len+2]='\0';
// 或者调用 strcat(PluralForm,"es");
}
//(2)如果单词后以y结尾,并且前面是一个辅音,将y改为ies
if(word[len-1]=='y' && !isVowel(word[len-2]))
{
flag = 3;
PluralForm[len-1]='i';
PluralForm[len]='e';
PluralForm[len+1]='s';
PluralForm[len+2]='\0';
}
// (3)如果单词以f或fe结尾,则把f或fe变成v, 再加es;
if(word[len-1]=='f')
{
flag = 4;
PluralForm[len-1]='v';
PluralForm[len]='e';
PluralForm[len+1]='s';
PluralForm[len+2]='\0';
}
if(word[len-2]=='f'&& word[len-1]=='e')
{
flag = 4;
PluralForm[len-2]='v';
PluralForm[len-1]='e';
PluralForm[len]='s';
PluralForm[len+1]='\0';
}
}
// 最后对仅仅加’s’的情况进行处理
if(flag==0)
{ // 此时
PluralForm[len]='s';
PluralForm[len+1]='\0';
}
//
strcpy(word, PluralForm);
return;
}
void MultiplePluralForm(char target[], char source[])
{
char word[40];
// 计算source字符串长度
int i=0;
while(source[i]!='\0')
i++;
int sourceLenth =i;
int tPos=0; //记录target数组的当前位置
int wPos=0; //记录source的当前字符位置
while(isspace(source[wPos]))
wPos++; //跳过空白字符
while(wPos<sourceLenth) // 从左到右扫描source字符串
{
//从source的当前位置取得一个单词, 记录在word中
int i=0;
while(!isspace(source[wPos])&& source[wPos]!='\0')
{
word[i]=source[wPos]; ///复制字符
i++; //更改word的当前位置
wPos++; //更改source字符串的当前位置
}
word[i]='\0';
RegularPluralForm(word); // 将当前单词转换为复数形式
//将word复制到数组target中
i=0;
while(word[i]!='\0')
{
target[tPos]=word[i]; //复制字符
tPos++; //更改目标字符串的当前位置
i++; //更改word的当前位置
}
target[tPos]=' '; //目标字符串加一个空格字符
tPos++; //更改目标字符串的当前位置
while(isspace(source[wPos]))
wPos++; //跳过空白字符
}
target[tPos]='\0';
return;
}
int main()
{
char str1[201];
char str2[400];
cin.getline(str1, 201,'\n');
MultiplePluralForm(str2, str1);
cout << str2 <<endl;
return 0;
}