一、问题介绍

UVA-10815

 

Sample Input
Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left."
So they went home.

 

Sample Output
a

adventures

blondes

came

disneyland

fork

going

home

in

left

read

road

sign

so

the

they

to

two

went

were

when

 

 

二、题解

set去重+getchar割词

 

三、实现代码

#include <iostream>
#include <stdio.h>
#include <set>

using namespace std;

int main()
{
    char c;
    set<string> ss;
    int i;
    while((c=getchar())!=EOF){
        string s;
        i=0;
        while((c>=65&&c<=90)||(c>=97&&c<=122)){
            if(c>=65&&c<=90)
                c=c+32;
            s+=c;
            i++;
            c=getchar();
        }
        if(i!=0){
            ss.insert(s);
        }
    }

    set<string>::iterator it;
    for(it= ++ss.begin();it != ss.end();it++){
        string s1=*it;
        cout<<s1<<endl;
    }

    return 0;
}

 

相关文章: