当前位置:编程学习 > C/C++ >>

UVa10815 - Andy's First Dictionary

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;
int main()
{
	string s;
	vector<string> svec;
	while(getline(cin,s))
	{
		int i;
		for(i=0;i<(int)s.size();++i)
		{
			if(isupper(s[i]))
				s[i]=s[i]-'A'+'a';
		}
		string::iterator begin=s.begin();
		for(;begin!=s.end()&&!isalpha(*begin);++begin);
		string::iterator end;
		if(begin==s.end())
			end=begin;
		else
			end=begin+1;
		while(true)
		{
			if(begin==s.end())
				break;
			for(;end!=s.end()&&isalpha(*end);++end);
			string str(begin,end);
			vector<string>::iterator iter=find(svec.begin(),svec.end(),str);
			if(iter==svec.end())
				svec.push_back(str);
			for(;end!=s.end()&&!isalpha(*end);++end);
			begin=end;
			if(end!=s.end())
				++end;
		}
	}
	sort(svec.begin(),svec.end());
	vector<string>::iterator iter=svec.begin();
	while(iter!=svec.end())
		cout<<*iter++<<endl;
	return 0;
}

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,