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<<*IT<&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. */