Problem1406--类的练习(STL)--set的应用

1406: 类的练习(STL)--set的应用

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 9  Solved: 7
[Submit] [Status] [Web Board] [Creator:]

Description

给出一串单词,把所有单词改小写去重按字典序输出。
set可以解决去重和排序问题。
set中每个元素最多只出现一次
set中的元素已经从小到大排序好
如何通过迭代器从小到大遍历所有元素 
for (set<string>::iterator i = d.begin(); i != d.end(); i++)  
cout << *i << endl;  


在主函数中输入字符串,把所有单词改小写去重按字典序输出。

Sample Input

Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road.The sign read:"Disneyland LEFT."
So they went home.

Sample Output

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when

HINT

set<类型> 名字; 
例如 set<int> se; set<string> se;
自己定义的结构体什么的也可以往里塞
struct POINT
{
    int x, y;
};
set<POINT> se;
基本操作对集合a中元素的有
插入元素:a.insert(1);
删除元素(如果存在):a.erase(1);
判断元素是否属于集合:if (a.find(1) != a.end()) ...
返回集合元素的个数:a.size()
将集合清为空集:a.clear()



Source/Category

 

[Submit] [Status]