joj 1274 Pig Latin 字符串处理

joj 1274 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):

  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.

 


虽然题目难度不是很大,但是对我启发挺大,碰到这种字符串处理的题,最好就是统一模式,
                  a=getchar():
                   while(flag)
           {      while()//判断是否符合条件
                 { ----   ,
                        if((a=getchar())==EOF)//获取a=getchar()
                                  flag=0;//判断文件是否结束
                  }
                   while()//判断是否符合条件
                 { ----   ,
                        if((a=getchar())==EOF)//获取a=getchar()
                                  flag=0;//判断文件是否结束
                  }
              }
#include < iostream >
#include
< cstdlib >
using   namespace  std;

  
int  main()
  {
 
//  freopen("s.txt","r",stdin);
 
//  freopen("key.txt","w",stdout);
   char  a;
  
int  flag = 0 ,e = 1 ,mark;
  
string  temp;
  
char  mar;
  a
= getchar();
  
while  (e)
  {
           mark
= 0 ;
            
while ((a >= ' a ' && a <= ' z ' ) || (a >= ' A ' && a <= ' Z ' ))
          {
            temp
= " ay " ;
             
if (flag == 0 )
            {
                 flag
++ ;
                 
if (a == ' A ' || a == ' a ' || a == ' E ' || a == ' e ' || a == ' I ' || a == ' i ' || a == ' O ' || a == ' o ' || a == ' U ' || a == ' u ' )
                 cout
<< a;
                 
else  
                {
                    mark
= 1 ;
                    mar
= a;
                }
           }
            
else
          cout
<< a;
          
if ((a = getchar()) == EOF)
                {
                    e
= 0 ;
                    
break ;
                 }    
         }
          
if (mark == 1 )
           {
                cout
<< mar;
           }    
          cout
<< temp;
           
while (a < ' A ' || a > ' z ' || (a > ' Z ' && a < ' a ' ))
           {
                cout
<< a;
                
if ((a = getchar()) == EOF)
                {
                    e
= 0 ;
                    
break ;
                 }    
           } 
           flag
= 0 ;   
  }
  
// system("PAUSE");
   return     0 ;
  }

你可能感兴趣的:(joj 1274 Pig Latin 字符串处理)