Pig-Latin 「爱情、让人受尽委屈。」 2023-01-08 03:27 122阅读 0赞 You have decided that PGP encryptation is not strong enough for your email. You have decided to supplement it by first converting your clear text letter into Pig Latin before encrypting it with PGP. Input and Output You are to write a program that will take in an arbitrary number of lines of text and output it in Pig Latin. Each line of text will contain one or more words. A “word” is defined as a consecutive sequence of letters (upper and/or lower case). Words should be converted to Pig Latin according to the following rules (non-words should be output exactly as they appear in the input): 1. Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just have the string “ay” (not including the quotes) appended to it. For example, “apple” becomes “appleay”. 2. Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should have the first consonant removed and appended to the end of the word, and then appending “ay” as well. For example, “hello” becomes “ellohay”. 3. Do not change the case of any letter. Sample Input This is the input. Sample Output hisTay isay hetay inputay. #include<iostream> using namespace std; char temp[1005]; int isab(char c) //是否是字母 { if(c>='a'&&c<='z') return 1; if(c>='A'&&c<='Z') return 1; return 0; } //是否是元音字母 int vowel(char c) { if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return 1; if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U') return 1; return 0; } int main() { while(gets(temp))//输入字符串数组 { int s=0,t=0;//设置两个标志变量 while(temp[s]) //如果不是字母,那么直接输出 if(!isab(temp[s])) { printf("%c",temp[s++]);//temp[0]输出,s+1 t=s; } else if(isab(temp[s]))//是字母 t++; else { if(!vowel(temp[s]))//辅音字母开头 { for(int i=s+1;i<t;++i) printf("%c",temp[i]);// printf("%c",temp[s]);// } else for(int i=s;i<t;++i)//以元音字母开头,i printf("%c",temp[i]);//输出元音字母开头的单词 printf("ay"); s=t;// } printf("\n"); } return 0; }
还没有评论,来说两句吧...