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

本文介绍了解决UVA10815问题的方法,重点讲解了如何利用tolower函数进行字符转换,isalpha函数进行字母判断,并通过stringstream实现字符串流操作,最终实现单词的提取和排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值