UVA 10815 Andy's First Dictionary (STL_set)

3 篇文章 0 订阅

题目传送门

题意:输入一个文本内容,将每个单词按照字典顺序输出,必须是小写字母。

题解:

刚学会的重定向,交上去忘记注释了,WA了一发。

isalpha()函数:判断字符是否为英文字母,若为英文字母,返回非0(小写字母为2,大写字母为1)。若不是字母,返回0。

tolower()函数:将字母转化为小写字母。

c++中,stringstream ss(str);表达的是什么意思??stringstream详细介绍用法点击这里

读取str中的单字,比如"hello world" ,就会读取hello和world。

 

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<sstream>
#define ms(arr) memset(arr, 0, sizeof(arr))
typedef long long ll;
using namespace std;
const int inf = 2147483647;
const int MAX = 1e5;
const int mod = 1e3;
set<string>z;
int main()
{
 //   freopen("in.txt","r",stdin);
 //   freopen("out.txt","w",stdout);
    string s1,buf;
    while(cin>>s1)
    {
        int len=s1.length();
        for(int i=0;i<len;i++)
        {
            if(isalpha(s1[i]))
            {
                s1[i]=tolower(s1[i]);
            }
            else
            {
                s1[i]=' ';
            }
        }
        stringstream ss(s1);
        while(ss>>buf)
        {
            z.insert(buf);
        }
    }
    for(set<string>::iterator it=z.begin();it!=z.end();it++)
    {
        cout<<*it<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值