Andy's First Dictionary (STL)

UVA - 10815

这个我主要wa在了单词的判断上来,以每次不是字母的字符为一个单词的结束,但没考虑到这个最后一个单词

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<string>
#include<iostream>
using namespace std;
char a[206];char b[206];
int main()
{
	set<string>p;
	while(gets(a))
	{
		memset(b,0,sizeof(b));
//		for(int i=0;i<strlen(a);i++)
//		printf("%c ",a[i]);
//		printf("\n");
		int k=-1;
		for(int i=0;i<strlen(a);i++)
		{
			if(a[i]>='A'&&a[i]<='Z')
			{
				a[i]=a[i]-'A'+'a';
			}
			if(a[i]>='a'&&a[i]<='z'&&i!=strlen(a)-1)
			{
				k++;b[k]=a[i];
			}
			else
			{
				if(i==strlen(a)-1&&a[i]>='a'&&a[i]<='z')
				{
					k++;b[k]=a[i];
				}
				if(k==-1)
				continue;
				string e=b;
				p.insert(e);
				k=-1;
				memset(b,0,sizeof(b));
			}
		}
	}
	set<string>::iterator ite;
	for(ite=p.begin();ite!=p.end();ite++)
	{
		cout<<*ite;printf("\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/liuliu2333/article/details/81151499
今日推荐