单词的提取

时间:2021-04-09 13:13:53   收藏:0   阅读:0

include

include<stdio.h>

include

include

include//按字典序输出

using namespace std;
vector words;
map<string,bool > dic;
int main()
{
//连续读入字符
string word;char c;
while(scanf("%c",&c)!=EOF)
{
if(c‘ ‘||c‘\n‘)
{
if(!word.empty()&&!dic[word])
{
words.push_back(word);
dic[word]=true;
word.clear();
}
}
else
{
if(c>=‘a‘&&c<=‘z‘)
{
word=word+c;
}
else if(c>=‘A‘&&c<=‘Z‘)
{
char nc=‘a‘+c-‘A‘;
word=word+nc;
}
else if(!word.empty()&&!dic[word])
{
words.push_back(word);
dic[word]=true;
word.clear();
}
}
}
sort(words.begin(),words.end());
/*
第一种输出方案
/
for(vector::iterator it=words.begin();it!=words.end();it++)
{
cout<<
it<<endl;
}

/*
第二种输出方案 (适用于c++11)
/
// for(auto it=words.begin();it!=words.end();it++)
// {
// cout<<
it<<endl;
// }

/*
第三种输出方案
*/
// for(int i=0;i<words.size();i++)
// {
// cout<<words.at(i)<<endl;
// }
return 0;
}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!