心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
遍历,找到所有单词,插入到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 阅读(372) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:字符串处理

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理