Question link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 1756
13913607 |
10815 |
Andy's first dictionary |
Accepted |
C ++ |
0.058 |
2014-07-20 14:02:39 |
13913568 |
10815 |
Andy's first dictionary |
Wrong answer |
C ++ |
0.175 |
2014-07-20 13:52:55 |
13913554 |
10815 |
Andy's first dictionary |
Wrong answer |
C ++ |
0.176 |
2014-07-20 13:48:07 |
13912818 |
10815 |
Andy's first dictionary |
Wrong answer |
C ++ |
0.172 |
2014-07-20 10:49:08 |
13911445 |
10815 |
Andy's first dictionary |
Wrong answer |
C ++ |
0.038 |
2014-07-20 05:43:58 |
Andy's first dictionary
Andy, 8, has a dream-he wants to produce his very own dictionary. this is not an easy task for him, as the number of words that he knows is, well, not quite enough. instead of thinking up all the words himself, he has a briliant idea. from his bookshelf he wowould pick one of his favorite story books, from which he wowould copy out all the distinct words. by arranging the words in alphabetical order , He is done! Of course, it is a really time-consuming job, and this is where a computer program is helpful.
You are asked to write a program that lists all the different words in the input text. in this problem, a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. words with only one letter are also to be considered. furthermore, your program must be case insensitive. for example, words like "apple", "apple" or "apple" must be considered the same.
Input
The input file is a text with no more than 5000 lines. An input line has at most 200 characters. input is terminated by EOF.
Output
Your output shoshould give a list of different words that appears in the input text, one in a line. the words shoshould all be in lower case, sorted in alphabetical order. you can be sure that he number of distinct words in the text does not exceed 5000.
Sample Input
Adventures in DisneylandTwo blondes were going to Disneyland when they came to a fork in theroad. The sign read: "Disneyland Left."So they went home.
Sample output
aadventuresblondescamedisneylandforkgoinghomeinleftreadroadsignsothetheytotwowentwerewhen
Problem-solving ideas: Pure pitfall questions, multiple spaces on the direct wa, there is no PE. Therefore, stream processing will be used in the future. In this way, spaces can be eaten.
1 #include <iostream> 2 #include <set> 3 #include <sstream> 4 #include <string> 5 #include <cctype> 6 using namespace std; 7 8 set<string> Set; 9 10 int main () {11 string s, buf;12 while (cin >> s) {13 for (int i = 0 ; i < s.size(); ++ i) {14 if (isalpha(s[i]))15 s[i] = tolower(s[i]);16 else17 s[i] = ‘ ‘;18 }19 stringstream ss(s);20 21 while (ss >> buf) Set.insert(buf);22 23 }24 for (set<string> :: iterator it = Set.begin(); it != Set.end(); it ++) {25 cout << *it << endl;26 }27 return 0;28 }