遍歷,找到所有單詞,插入到set中即可。
以下是我的代碼:
#include<iostream>
#include<string>
#include<set>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
/*
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
//*/
string s;
char ch;
while((ch=getchar())!=EOF)
s+=tolower(ch);
set<string> dictionary;
for(int i=0;i<s.size();i++)
{
string t;
while(i<s.size() && isalpha(s[i]))
{
t+=s[i];
i++;
}
if(!t.empty())
dictionary.insert(t);
}
for(set<string>::iterator i=dictionary.begin();i!=dictionary.end();i++)
cout<<*i<<endl;
return 0;
}
posted on 2011-04-07 19:18
lee1r 閱讀(403)
評論(0) 編輯 收藏 引用 所屬分類:
題目分類:字符串處理