UVA10815 Andy's First Dictionary【字符串处理】

问题描述

输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出。单 词不区分大小写。

样例输入

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.

样例输出

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

解题思路:由于大小写不敏感,因此将所有的字母变为小写,将非字母的字符变成空格,然后使用strtok函数进行分割,将分割后的单词放入STL的set中,最后打印即可。注意:要选用C++11

AC的C++程序:

#include
#include
#include
#include
#include
#include

using namespace std;
setdict;

void split(char *s)
{
	char *sp=strtok(s," ");
	while(sp)
	{
		dict.insert(sp);
		sp=strtok(NULL," ");
	}
}

const int N=10000;
char s[N];

int main()
{
	dict.clear();
	while(gets(s))
	{
		for(int i=0;i::iterator it=dict.begin();it!=dict.end();it++)
	  cout<<*it<

 

你可能感兴趣的:(算法)