10815 - Andy's First Dictionary
来源:互联网 发布:微信小程序 源码下载 编辑:程序博客网 时间:2024/05/21 10:18
Andy, 8, has a dream - he wants to produce his very owndictionary. This is not an easy task for him, as the number of words that heknows is, well, not quite enough. Instead of thinking up all the words himself,he has a brilliant idea. From his bookshelf he would pick one of his favoritestory books, from which he would copy out all the distinct words. By arrangingthe words in alphabetical order, he is done! Of course, it is a reallytime-consuming job, and this is where a computer program is helpful.
You are asked to write a program that lists all thedifferent words in the input text. In this problem, a word is defined as aconsecutive sequence of alphabets, in upper and/or lower case. Words with onlyone 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
Theinput file is a text with no more than 5000 lines. An input line has at most200 characters. Input is terminated by EOF.
Output
Your output should give a list of different words thatappears in the input text, one in a line. The words should all be in lowercase, sorted in alphabetical order. You can be sure that the number of distinctwords in the text does not exceed 5000.
SampleInput
Adventuresin Disneyland
Two blondes were going to Disneyland when they came toa fork in the
road. The sign read: "Disneyland Left."
So they went home.
SampleOutput
a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
代码(WA了,没找到错误):
#include<iostream>
#include<cctype>
#include<set>
#include<string>
using namespacestd;
set<string>ss;
set<string>::iteratorit;
int main()
{
char ch;
string s="";
while(cin.get(ch))
{
if(isalpha(ch))
{
s=s+(char)tolower(ch);
}
else
{
ss.insert(s);
s="";
}
}
for(it=ss.begin();it!=ss.end();it++)
{
cout<<*it<<endl;
}
return 0;
}
- 10815--Andy's First Dictionary
- 10815 Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- 10815 - Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- Andy's First Dictionary
- 400 - Unix ls
- 540 - Team Queue
- 814 - The Letter Carrier's Rounds
- 1592 - Database
- 10474 - Where is the Marble
- 10815 - Andy's First Dictionary
- 12096 - The SetStack Computer
- 212 - Use of Hospital Facilities
- HDU 1575 Tr A (矩阵快速幂)
- UVa 11375 Matches
- 230 - Borrowers
- 511 - Do You Know the Way to San Jose
- 822 - Queue and A
- PHP中错误控制@运算符