📄 pex2_6.cpp
字号:
#include <iostream.h>
#include <string.h>
#include <ctype.h>
// determine if ch is a vowel
int isvowel(char ch)
{
char lower= tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return 1;
else
return 0;
}
void main(void)
{
char word[20];
// piglatin equiv. of word. endconsonant used to append
// 1st char of word and "ay" when word begins with consonant
char piglatin[22], endconsonant[4] = "xay";
// read words until end of file. no attempt
// is made to preserve word spacing in the output
while(cin >> word)
{
if (isvowel(word[0]))
{
strcpy(piglatin,word);
strcat(piglatin,"ay");
}
else
{
strcpy(piglatin, &word[1]);
endconsonant[0] = word[0];
strcat(piglatin,endconsonant);
}
cout << piglatin << " ";
}
cout << endl;
}
/*
<Run>
This is a sentence with pig latin
hisTay isay aay entencesay ithway igpay atinlay
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -