uva 10815 set的用法
来源:互联网 发布:淘宝长尾词是什么意思 编辑:程序博客网 时间:2024/06/05 05:55
本题主要学习的就是set的用法。。也知道set中元素有着从小到大排好序的性质。。
代码,详情见注释
#include<iostream>#include<cctype>#include<set>#include<string>#include<sstream>using namespace std;set<string> dict;int main (){string s,buf;while (cin >> s){int i;for(i=0;i<s.size();i++){if(isalpha(s[i])) //判断是否为字母 类似的函数还有isupper islower isdigit s[i]=tolower(s[i]); //将字母转化成小写 类似的还有toupper else s[i]=' '; //此处将不是字母的都转化为空格 而stringstream会滤掉空格 最后只会剩下单词 }stringstream ss(s);//ss>>buf; 不能写成这样 因为有可能在单词前面有标点 而在上面被转化成了空格就无法读入单词,还是应该用while将流中的东西读干净~ while(ss >> buf)dict.insert(buf); //插入到set中 set保证里面的元素不重复 }set<string>::iterator it; //此处为STL中的迭代器。。 要记住用法.begin() .end() for(it=dict.begin();it!=dict.end();it++)cout << *it << endl;return 0;}
0 0
- uva 10815 set的用法
- set有关的函数的用法(The SetStack Computer UVA
- 经典第五章 例 5-3 UVa 10815 Andy's First Dictionity (set的用法)
- Andy's First Dictionary(uva 10815) set用法
- UVA 10815 【set的使用】【字符串模拟】
- UVA 10815 set
- UVa 10815 set
- SET XACT_ABORT 的用法
- SET NOCOUNT 的用法
- SET ANSI_NULLS的用法
- SET IDENTITY_INSERT的用法
- SET CONCAT_NULL_YIELDS_NULL的用法
- SET XACT_ABORT 的用法
- SET NOCOUNT 的用法
- SET命令的用法
- SET IDENTITY_INSERT 的用法
- set 命令的用法
- set 命令的用法
- 理解Docker(译文)
- 如何制作一个360度全景
- hdu 1069 Monkey and Banana 再来一波DP啦~~LIS的变形,会最大上升子序列就可以A啦~
- Python open() 函数 文件处理
- C语言BNF范式
- uva 10815 set的用法
- c中malloc calloc realloc 的区别和联系
- 乱码的艺术
- IO 相关指标
- Kruskal最小生成树算法
- rockethon2015 B题 Permutations 规律+构造
- Scala ListBuffer使用备忘
- Apache Storm提交Topology时的默认CLASSPATH问题
- ClassNotFoundException when unmarshalling 问题总结