UVA492 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.

问题链接:UVA492 Pig-Latin
问题简述:(略)
问题分析
    一个简单的文本处理题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA492 Pig-Latin */

#include 

using namespace std;

bool isvowel(char c)
{
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
            c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
}

int main()
{
    string s;
    while(getline(cin, s)) {
        for(int i = 0, j = 0; s[i]; ) {
            if(!isalpha(s[i])) {
                putchar(s[i++]);
                j = i;
            } else if(isalpha(s[j]))
                j++;
            else {
                if(!isvowel(s[i])) {
                    for(int k = i + 1; k < j; k++)
                        putchar(s[k]);
                    putchar(s[i]);
                } else
                    for(int k = i; k < j; k++)
                        putchar(s[k]);
                printf("ay");
                i = j;
            }
        }
        putchar('\n');
    }

    return 0;
}

你可能感兴趣的:(#,ICPC-备用二,#,ICPC文本,#,ICPC-UVA,UVA492,Pig-Latin)