UVA483 Word Scramble【Ad Hoc+单词逆序】

Write a program that will reverse the letters in each of a sequence of words while preserving the orderof the words themselves.

Input

The input file will consist of several lines of several words. Words are contiguous stretches of printablecharacters delimited by white space.

Output

The output will consist of the same lines and words as the input file. However, the letters within eachword must be reversed.

Sample Input

I love you.

You love me.

We're a happy family.

Sample Output

I evol .uoy

uoY evol .em

er'eW a yppah .ylimaf


问题链接:UVA483 Word Scramble

问题简述:(略)

问题分析:(略)

程序说明

  单词逆序输出问题,可以使用堆栈来实现。但是,这里给出的程序是用数组下标来记忆已经输出的位置实现逆序输出。

题记:(略)

参考链接:(略)


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

/* UVA483 Word Scramble */

#include 

using namespace std;

int main()
{
    string s;

    while(getline(cin, s)) {
        int i, p = 0;
        for(i=0; s[i]; i++) {
            if(s[i] == ' ') {
                for(int j=i-1; j>=p; j--)
                    putchar(s[j]);
                putchar(s[i]);

                p = i + 1;
            }
        }
        for(int j=i-1; j>=p; j--)
            putchar(s[j]);
        putchar('\n');
    }

    return 0;
}



你可能感兴趣的:(#,ICPC-备用二,#,ICPC-Ad,Hoc,#,ICPC-UVA)