Set-----集合入门

函数中的集合和  数学中的集合 基本上差不多 集合中每个元素最多只能出现一次  并且 当元素储存到set集合之中 会自动 按照 ascll 进行  从小到大的  排序

大神关于   set   的 详细总结    http://www.cnblogs.com/BeyondAnyTime/archive/2012/08/13/2636375.html

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.
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 should give a list of different words that appears in the input text, one in a line. The
words should 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 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
 1 #include<iostream>
 2 #include<string>
 3 #include<set>
 4 #include<sstream>
 5 using namespace std;
 6 set<string>dict;       //  定义一个 set  集合
 7 int main()
 8 {
 9     string s,buf;
10     while(cin>>s)
11     {
12         for(int i=0;i<s.length();i++)
13         {
14             if(isalpha(s[i]))            // 如果是  字母的话  返回  非零值
15                 s[i]=tolower(s[i]);    //  将 大写字母转换为 小写的 函数
16             else
17                 s[i]=‘ ‘;     //  将所有的 大写字母[ 转化 为小写  然后   不是字母的转化为  空格
18         }
19             stringstream ss(s);     //  将一段话  分割 开   转化成一个个的单词
20             while(ss>>buf)
21                 dict.insert(buf); /*这一种对文本处理的 方式 很好*/
22     }
23     for(set<string>::iterator it=dict.begin();it!=dict.end();++it)
24         cout<<*it<<endl;
25     return 0;
26 }
时间: 2024-08-26 12:58:55

Set-----集合入门的相关文章

java集合入门和深入学习,看这篇就差不多了

一.集合入门总结 集合框架: Java中的集合框架大类可分为Collection和Map:两者的区别: 1.Collection是单列集合:Map是双列集合 2.Collection中只有Set系列要求元素唯一:Map中键需要唯一,值可以重复 3.Collection的数据结构是针对元素的:Map的数据结构是针对键的. 泛型: 在说两大集合体系之前先说说泛型,因为在后面的集合中都会用到:所谓的泛型就是:类型的参数化 泛型是类型的一部分,类名+泛型是一个整体 如果有泛型,不使用时,参数的类型会自动

《day18_String练习_基本类型包装类_集合入门》

1 package cn.itcast.api.String.test; 2 3 public class StringTest_1 { 4 5 public static void main(String[] args) { 6 7 String s1 = "asdfitcastghijfghjk"; 8 String s2 = "xcitcastvbnm"; 9 10 String maxSubStirng = getMaxSubstring(s2, s1);

数组集合入门

原文地址:https://www.cnblogs.com/wujianbo123/p/10987638.html

《Java从入门到放弃》JavaSE入门篇:集合

今天来讲讲Java中的集合和常见集合类型的使用. 什么是集合呢? 刚好最近学校里面军训,只听到教官一声喊:"集合!!!"各位小萌新们就屁颠屁颠的跑过来排列整齐了,这就是集合··· Java中的集合也是一样的意思,Java一声喊:"集合!!!",那么我们就把需要放在一起的数据放到一个集合中.有的人会说"数组不就有这个功能么".是的,数组是有这个功能,但集合与数组相比,功能会更多些,而且不同的集合侧重点不一样,具体有哪些优势,我们接下来讲解. 集合与

Java入门(三)——集合概讲

集合(或者叫容器)是Java的核心知识点,它有着很深的深度.我们这里不会设计多深,仅仅作为了解入门,深入了解请移步各种集合源码文章.好的,下面正是开始介绍... Java集合为何而生 我们知道,Java是一门面向对象编程语言,这也就意味着程序中存在着大量的对象.这个时候问题就来了,我们如何很好的存放和操作对象呢?如果你能明白这个问题,那么你就知道了"集合为何而生"这个问题的答案. 总结一句: Java给我们提供了工具(集合)方便我们去存放和操作多个Java对象 Java集合入门学习 J

集合大总结

1.集合入门总结 2.集合常见方法 3.List和Set的区别 4.List集合的总结 5.Set集合总结 6.Map集合总结

Java 集合系列之二:List基本操作

1. Java List 1. Java List重要观点 Java List接口是Java Collections Framework的成员. List允许您添加重复元素. List允许您拥有'null'元素. List接口在Java 8中有许多默认方法,例如replaceAll,sort和spliterator. 列表索引从0开始,就像数组一样. List支持泛型(类型的参数化),我们应尽可能使用它.将Generics与List一起使用将在运行时避免ClassCastException. 2

Swift入门篇-集合

一:数组 一:可变数组 定义:数组使用有序列表存储相同类型的多重数据. 格式: 第一种格式 var 变量: 类型[] = [变量值,变量值,...] 第二种格式 var 变量 =[变量值,变量值,...] 说明: 1:[变量值,变量值...] 这样表示数组 ,前提是 变量值的类型必须一值.(和其他语言有所不同) 2:上面两种格式都是定义一个数组,数组中的变量值的类型必须一致 3:第一种格式定义的数组,是直接定义数组,第二种格式定义的数组 是编译器通过类型值推导出是数组格式 注意点 1:常量关键字

初学者入门web前端 C#基础知识:数组与集合

对于初学者,想要入门web前端,要有足够的信念和坚持,不然只会越走越远,我现在就深深的体会到. 我本是一个很拒绝代码的人,以前想过UI设计,但是在这段学习时间里,发现其实只要认真,代码并不是很难 所以我整理了一套前期学C#的知识点,对于后期学习JavaScript有很大的帮助. 一.数组与集合数组:能存放任意多个同类型的数据 数据项:类型相同 ①每一个数据型都有一个编号(索引或下标) ②数据的索引(下标)是一个int类型的数字 ③从0开始,依次为数据中每一个数组项编号 数组的声明与赋值 声明:数

Dart入门—集合类型

Dart入门-集合类型 Dart核心库提供了List(列表).Map(映射).Set(集)三种集合类型 列表(List) 固定长度的列表,一旦定义就无法改变长度 List<int> fixedLengthList = new List(5); fixedLengthList[0] = 87; print(fixedLengthList); print(fixedLengthList[0]); 可改变长度的列表,可以根据需要改变长度 List<int> growableList =