Pig-Latin
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.
#include<iostream> /*面向过程思想的程序设计*/
#include<string>
#include<cctype>
using namespace std;
int isVowel(char alpa);
int main()
{
string st="";
while(getline(cin,st)){
int j;
for(int i=0;i<st.length();i++){
if(isalpha(st[i])){ //如果是字符就进入循环判断
if(!isVowel(st[i])){
for(j=i+1;isalpha(st[j]);j++) //j变量用于循环单词
cout<<st[j]; //输出字符
cout<<st[i]<<"ay"; //输出首字母和结尾ay
}
else{
for(j=i;isalpha(st[j]);j++)
cout<<st[j];
cout<<"ay";
}
i=j-1; //因为循环有i++,故要记录上一个字符的序号
}
else
cout<<st[i]; //不是字符就直接输出
}
cout<<endl;
}
return 0;
}
int isVowel(char alpa){
switch(alpa){
case 'a':case 'e':case 'i':case 'o':case 'u':
case 'A':case 'E':case 'I':case 'O':case 'U':return 1;
default: return 0;
};
}
#include<iostream> /*面向对象思想的程序设计*/
#include<string>
#include<cctype>
using namespace std;
int isVowel(char alpa);
int main()
{
string st="",buf="";
int i,j;
while(getline(cin,st)){
for(i=0;i<st.length();){
if(isalpha(st[i])){
for(j=0;isalpha(st[i]);){
buf[j++]=st[i++];
}
buf[j]='\0'; /*记录一个单词*/
if(isVowel(buf[0])){
cout<<&buf[0]<<"ay";
}
else if(!isVowel(buf[0])){
cout<<&buf[1]<<buf[0]<<"ay";
} /*输出一个单词*/
}
else{
cout<<st[i++];
}
}
cout<<endl;
}
return 0;
}
int isVowel(char alpa){
switch(alpa){
case 'a':case 'e':case 'i':case 'o':case 'u':
case 'A':case 'E':case 'I':case 'O':case 'U':return 1;
default: return 0;
};
}
#include<iostream> /*面向对象思想采用了类和对象的程序设计*/
#include<string>
#include<cctype>
using namespace std;
class Words{ //单词类
private:
string word;
bool isVowel(const char &alpa);
public:
int Readword(const string &st,int i);
void Printword();
};
int main()
{
string st="";
while(getline(cin,st)){
for(int i=0;i<st.length();){
if(isalpha(st[i])){
Words myword;
i=myword.Readword(st,i);
myword.Printword();
}
else{
cout<<st[i++];
}
}
cout<<endl;
}
return 0;
}
bool Words::isVowel(const char &alpa){
switch(alpa){
case 'a':case 'e':case 'i':case 'o':case 'u':
case 'A':case 'E':case 'I':case 'O':case 'U':return true;
default: return false;
};
}
int Words::Readword(const string &st,int i){
int j;
for(j=0;isalpha(st[i]);){
word[j++]=st[i++];
}
word[j]='\0';
return i;
}
void Words::Printword(){
if(isVowel(word[0])){
cout<<&word[0]<<"ay";
}
else{
cout<<&word[1]<<word[0]<<"ay";
}
}
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int isVowel(char alpa); /*return 1 if it is a vowel else return 0*/
int main()
{
char sentence[100000],buf[100000];
int i,j;
while(fgets(sentence,100000,stdin)){
for(i=0;i<strlen(sentence);){
if(isalpha(sentence[i])){
for(j=0;isalpha(sentence[i]);){
buf[j++]=sentence[i++];
}
buf[j]='\0';
if(isVowel(buf[0])){
printf("%say",&buf[0]);
}
else if(!isVowel(buf[0])){
printf("%s%cay",&buf[1],buf[0]);
}
}
else{
printf("%c",sentence[i++]);
}
}
}
return 0;
}
int isVowel(char alpa){
switch(alpa){
case 'a':case 'e':case 'i':case 'o':case 'u':
case 'A':case 'E':case 'I':case 'O':case 'U':return 1;break;
default: return 0;
};
}
/* while(fgets(sentence,100000,stdin)){
for(i=0;i<strlen(sentence);i++){
if(isalpha(sentence[i])){
if(isVowel(sentence[i])){
for(j=i;isalpha(sentence[j]);j++){
printf("%c",sentence[j]);
}
printf("ay");
}
else{
for(j=i+1;isalpha(sentence[j]);j++){
printf("%c",sentence[j]);
}
printf("%cay",sentence[i]);
}
i=j-1;
}
else{
printf("%c",sentence[i]);
}
}
}*/