UVA

/*
  收获:
  1. set是数学上的集合,每个元素最多出现一次,和sort函数一样,自定义类型也可定义set,但必须定义小于运算符
  关于STL中的set,可见改blog:
  http://blog.csdn.net/sunshinewave/article/details/8068326
  
  2. string类中除了size()以外,也有和它意义用法基本一样的length():
  http://blog.csdn.net/caomiao2006/article/details/4814927
  
  3. 有用的函数:
     isalpha, tolower, 还有以前用过的, isdigit, 在很多时候,可以极大简化代码
	 另,上面几个函数都是在 <cctype> 头文件中
	 
  4. set<string>::iterator 表示的时迭代器,是STL的一个概念,类似于指针(类似是指用法类似)
     注意:string中也有迭代器,且之前做题时也遇到过
	 
	 题号:UVA - 11809 Floating-Point Numbers
	 链接: http://blog.csdn.net/mofushaohua_ln/article/details/77415016
	 
	 当时这题里面有这样一句代码
	 for (string::iterator i = in.begin(); i != in.end(); i++)
			if (*i == 'e') *i = ' ';
			
	就是用到了string的迭代器
	
	此外,之前做题时,有了解到反迭代器,有关blog一并放上
	http://blog.csdn.net/kjing/article/details/6936325
	 
  
  评价:
  本题技巧不多,主要思路就是,用set保存单词集合,同时,输入时把所有非字母的字符变成空格,然后用 stringstream 得到各个单词
*/



#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <cctype> 
using namespace std;
set<string> dict; //string集合
typedef set<string>::iterator p;
//#define debug

int main()
{	
	#ifdef debug
	freopen("E:\in.txt", "r", stdin);
	freopen("E:\out.txt", "w", stdout);
	#endif
	string s, buf;
	while (cin >> s)
	{
		for (int i = 0; i < s.length(); i++)
			if (isalpha(s[i])) s[i] = tolower(s[i]);
			else s[i] = ' ';
			
			stringstream ss(s);
			while (ss >> buf)
			dict.insert(buf);
	}
	for (p it = dict.begin(); it != dict.end(); it++)
		cout << *it << endl;	
	#ifdef debug
	fclose(stdin);
	fclose(stdout);
	#endif
	return 0;
} 


原文地址:https://www.cnblogs.com/mofushaohua/p/7789461.html