uva 492 Pig_Latin 题目详解及面向过程,面向对象的编程思想的粗略讲解

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 (aeio, 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 AaEeIiOoU 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.



(以下很多名词由博文作者设计,旨在意会,不要深究.)
一.翻译:
翻译是没有必要的,这些题目的内容没有想象中那么困难,如果实在不会的,就用蹩脚的网络翻译,再加上一丢丢的英语基础,要完全理解内容是没有问题的.
技巧:先看输入输出样例,然后看输入输出要求.

二.本题亮点:
1. 如果不用编程只用想的话,这个题 非常非常简单.如果要编程的话......就 非常简单.
2.Pig-Latin:故意颠倒英语字母顺序拼凑而成的行话.
3.本题主要考察的是大家对于字符串的理解和运用能力.
三.设计解题代码: /*设计:即采用的语法方式*/
1.面向过程设计:不采用类,对象的经典语言方法.
四..比较:
1.面向对象和面向过程设计的好处和坏处?

#include    /*面向过程思想的程序设计*/  
#include  
#include  
using namespace std;  
int isVowel(char alpa);  
  
int main()  
{  
    string st="";  
    while(getline(cin,st)){  
        int j;  
        for(int i=0;i//不是字符就直接输出
        }  
        cout<



#include           /*面向对象思想的程序设计*/  
#include  
#include  
using namespace std;  
int isVowel(char alpa);  
int main()  
{  
    string st="",buf="";  
    int i,j;  
    while(getline(cin,st)){  
        for(i=0;i


#include           /*面向对象思想采用了类和对象的程序设计*/  
#include  
#include  
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



======无法AC  WA or Runtime Error
#include 
#include 
#include 
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

你可能感兴趣的:(uva)