您的位置:首页 > 其它

set的一些用法和C中一些函数

2014-12-02 13:16 281 查看
//UVA10815

//tolower函数功 能: 把字符转换成小写字母,非字母字符不做出处理

//isalpha函数判断字符ch是否为英文字母,若为小写字母,返回2,若为大写字母,返回1。若不是字母,返回0。在标准c中相当于使用“isupper(ch)||islower(ch)”做测试,

//

stringstream是字符串流。它将流与存储在内存中的string对象绑定起来。

在多种数据类型之间实现自动格式化。
#include <iostream>
#include<set>
#include<string>
#include<sstream>
#include<stdio.h>
using namespace std;
set<string>dict;
int main()
{
   // freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    string word1,word2;
    while(cin>>word1)
    {
        int i;
        for(i=0;i<word1.length();i++)
        {
            if(isalpha(word1[i]))
               word1[i]=tolower(word1[i]);
            else
                word1[i]=' ';

        }
        stringstream ss(word1);
        while(ss>>word2)
           {
                dict.insert(word2);
               // cout<<1<<endl;
           }
    }

        for(set<string>::iterator it=dict.begin();it!=dict.end();it++)
            cout<<*it<<endl;
    
        return 0;

   // fclose(stdin);
   // fclose(stdout);
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: