zoukankan      html  css  js  c++  java
  • uva10815(set的应用)

    紫书例题,这道题的例程让我长了知识。以前没有用过cctype和stringstream相关的东西。很实用,值得学习。

    #include <cctype>的函数

    c++中应该是#include <cctype>

    c中应该是#include <ctype.h>

    以下为字符函数库中常用的函数:

    函数名称 返回值
    isalnum() 如果参数是字母数字,即字母或数字,该函数返回true
    isalpha() 如果参数是字母,该函数返回真
    isblank() 如果参数是空格或水平制表符,该函数返回true
    iscntrl() 如果参数是控制字符,该函数返回true
    isdigit() 如果参数是数字(0~9),该函数返回true
    isgraph() 如果参数是除空格之外的打印字符,该函数返回true
    islower() 如果参数是小写字母,该函数返回true
    isprint() 如果参数是打印字符(包括空格),该函数返回true
    ispunct() 如果参数是标点符号,该函数返回true
    isspace()

    如果参数是标准空白字符,如空格、进纸、换行符、回车

    、水平制表符或者垂直制表符,该函数返回true

    isupper() 如果参数是大写字母,该函数返回true
    isxdigit() 如果参数是十六进制的数字,即0~9、a~f、A~F,该函数返回true
    tolower() 如果参数是大写字符,则返回其小写,否则返回该参数
    toupper() 如果参数是小写字母,则返回其大写,否则返回该参数
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<cctype>
    #include<sstream>
    using namespace std;
    #define INF 1000000000
    #define eps 1e-8
    #define pii pair<int,int>
    #define LL long long int
    #define maxn 100009
    string s,buf;
    set<string>dict;
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        while(cin>>s)
        {
            int len=s.length();
            stringstream ss;
            for(int i=0;i<len;i++)
            {
                if(isalpha(s[i])) s[i]=tolower(s[i]);
                else s[i]=' ';
            }
            ss<<s;
    /*也可以ss.str(s),如果清空ss的内容就用ss.str("")。注意ss.str(s)是覆盖掉ss中原来的东西,而ss<<s是在后面添加上s*/
    while(ss>>buf)//空格都不会传 { dict.insert(buf); } } for(set<string>::iterator it=dict.begin();it!=dict.end();it++) //注意不能写成it<dict.end(),只有等与不等 cout<<*it<<endl; return 0; }
  • 相关阅读:
    [Compose] 12. Two rules about Funtors
    [Compose] 11. Use Task for Asynchronous Actions
    [React Native] Animate Styles of a React Native View with Animated.timing
    [Compose] 10. Capture Side Effects in a Task
    [Angular Router] Lazy loading Module with Auxiliary router
    注重实效的程序员——途径篇
    UVa 674: Coin Change
    apache POI 导出excel相关方法
    Java调用R(二)_JRI
    drp用户管理完成后,asp.net与java的一个简单比较
  • 原文地址:https://www.cnblogs.com/zywscq/p/3979958.html
Copyright © 2011-2022 走看看