Title

单词的提取

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;
}

posted @ 2021-04-08 19:39  BeautifulWater  阅读(80)  评论(0编辑  收藏  举报