UVA 10815 Andy ' s first Dictionary (Stl,set)

Source: Internet
Author: User

UVA 10815 Andy's first Dictionary
title: Give a string of words and change all the words to lowercase to re-export them in dictionary order.
Idea: Set can solve the problem of de-weight and sorting. (This is critical, from small to large)
set each element at most once
how to traverse through the iterator all elements from small to large
for (set::iterator i = D.begin (); I! = D.end (); i++)
cout << *i << Endl;

#include <iostream> #include <string> #include <set> using namespace std;
set<string>jihe;
    int main () {string S;
        while (Getline (cin,s)) {string tmp;
                for (int i=0;i<=s.size (); i++) {if (s[i]>= ' A ' &&s[i]<= ' Z ') {
                s[i]=s[i]+32;

            Tmp+=s[i];
            } else if (s[i]>= ' a ' &&s[i]<= ' Z ') {tmp+=s[i];
                    } else {if (!tmp.empty ()) {Jihe.insert (TMP);
                Tmp.clear ();
    }}} if (!tmp.empty ()) Jihe.insert (TMP); } for (Set<string>::iterator it=jihe.begin (); It!=jihe.end (); it++) {COUT&LT;&LT;*IT&LT;&L
        T;endl;
} return 0; }/* Adventures in Disneyland, blondes were going to Disneyland, they came to a fork in the

Road.
The sign read: "Disneyland left."

So they went home. */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.