这次是一道字符串处理题,不是很难。
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):
- 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”. - 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”. - Do not change the case of any letter.
Sample Input
This is the input.
Sample Output
hisTay isay hetay inputay.
题目要求大体如下
给很多行,每行都是字符串,然后判断字符串是不是英语单词,如果不是照常输出,如果是,判断是不是元音字母开头,如果是元音字母开头则把在最后加上“ay" 再输出
例如:
apple -> appleay
如果不是元音字母就要把第一个字母移到最后并且加上“ay”再输出
例如:
home->omehay
且无论大小写都是如此。
给一个思路:
在此给一个例子
“.hello world.”
这么看.hello算是一个单词嘛,显然不是的,hello是一个单词
应该输出.ellohay orldway.
所以说要先找到第一个字母才能进行单词的判断.
#include<stdio.h>
int zimu(char n){//函数来判断是不是字母
if((n>='A'&&n<='Z')||(n>='a'&&n<='z')){
return 1;
}
return 0;
}
int yuanyin(char n){/函数来判断某个字母是不是元音
if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u'||n=='A'||n=='E'||n=='I'||n=='O'||n=='U'){
return 1;
}
return 0;
}
int main()
{
int a,b,c,d,e;
char n[1000000];
while(gets(n)!=0){
b=0;
while(n[b]!='\0'){
if(zimu(n[b])==1){
a=b;
while(zimu(n[b])==1){
b=b+1;
}
if(yuanyin(n[a])==1){
c=a;
while(c<b){
printf("%c",n[c]);
c=c+1;
}
printf("ay",n[a]);
}
if(yuanyin(n[a])!=1){
c=a+1;
while(c<b){
printf("%c",n[c]);
c=c+1;
}
printf("%cay",n[a]);
}
}
else{
printf("%c",n[b]);
b=b+1;
}
}
printf("\n");
}
}
代码内容我觉得还算易懂.
祝在看的各位早日有所作为,下次再见.