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 would pick one of his favourite story books, from which he would 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.

 

Andy's First Dictionary_第1张图片

Andy's First Dictionary_第2张图片

就一个字典序嘛,set直接搞定。

#include
#include
#include
#include
using namespace std;
set dict;
int main()
{
	string s,temp;
	while(cin>>s){
		
		temp.clear();
		for(int i=0;i>temp)
			dict.insert(temp);
	}
	
	for(set::iterator it = dict.begin();it!=dict.end();it++){
			cout<<*it<

关于这些输入什么的我还不是很熟悉。

1.cin>>s,是不需要写!=EOF的,

2.string 是不可以用scanf("%s",s)的。

3.stringstream 我不是很会用,同桌教我的,就咱们从键盘获得输入流,用cin>>,那这个是从字符串获得输入流。

方式是stringstream ss(s);

然后这个流自动以空格区分。

挨个加到set里面去就可以了。

set的性质

     自动去重

     自动排序

你可能感兴趣的:(Andy's First Dictionary)