UVa 10815 Andy's First Dictionary
2014-10-15 14:36
363 查看
题意:
输入一段文本,找出所有不同的单词,并按字典序由小到大输出,单词不区分大小写。
思路:
输入时将所有的非字母元素转化为空格,在进行字符串的解析即可。stringstream在解析字符串是以空格或回车作为结束标志。
输入一段文本,找出所有不同的单词,并按字典序由小到大输出,单词不区分大小写。
思路:
输入时将所有的非字母元素转化为空格,在进行字符串的解析即可。stringstream在解析字符串是以空格或回车作为结束标志。
#include <set> #include <stdio.h> #include <string.h> #include <sstream> #include <iostream> #include <algorithm> using namespace std; set <string> word; set <string>::iterator iter; int main(){ // freopen("in.txt", "r", stdin); string s,buf; while(cin >> s){ for(int i=0; i<s.length(); i++){ if(isalpha(s[i])) s[i] = tolower(s[i]);///isalpha()判断字符是否是字母,tolower()将字母转换为小写 else s[i] = ' '; } stringstream ss(s);///解析字符串 while(ss >> buf) word.insert(buf);///将解析结果ss存入buf中放入集合排序 } for(iter = word.begin(); iter != word.end(); iter++)///遍历集合 cout << *iter << endl; return 0; }
相关文章推荐
- uva 10815 Andy's First Dictionary(字符串排序)
- UVA10815 Andy's First Dictionary
- uva -- 10815 Andy's First Dictionary
- UVa 10815 Andy's First Dictionary (分离字符串)
- uva 10815 Andy's First Dictionary
- uva-10815 - Andy's First Dictionary
- uva - 10815 - Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- Uva 10815 Andy's First Dictionary (字典序)
- UVA - 10815 Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- uva 10815 Andy's First Dictionary
- UVa:10815 - Andy's First Dictionary
- uva10815 - Andy's First Dictionary
- UVA - 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- Uva 10815-Andy's First Dictionary(串)
- UVa 10815 - Andy's First Dictionary解题报告
- UVA - 10815 Andy's First Dictionary