首页 > 其他 > 详细

UVa 10815

时间:2015-02-05 16:31:57      阅读:250      评论:0      收藏:0      [点我收藏+]
背景:这题只能照着书敲,学习C++的用法,主要学习见对代码的注解。
#include<iostream>
#include<sstream>    //流的头文件
#include<iterator>
#include<cctype>    //isalpha()的头文件,类似的还有isdigit()
#include<string>
#include<set>
using namespace std;
set<string>  set1;

int main(void){
    string string1,temp_string;
    while(cin>>string1){    //C++输入流如果遇见eof会返回false,cin遇到空格,TAB,回车都结束读取,并且回车符被消耗。<span id="transmark"></span>
        for(int i=0;i < string1.size();i++){
            if(isalpha(string1.at(i))) string1.at(i)=tolower(string1.at(i));    //char tolower(char c);char toupper(char c);大小写转换在iostream中
            else string1.at(i)=' ';    //这里的思路很巧妙,把标点符号转换为空格,这样再把这个空格和字母混合的string1传入流中,流传出为真正的string
        }
        stringstream ss(string1);    //创建一个string的流,并把string1导入流中
        while(ss >> temp_string) set1.insert(temp_string);    //从流里导出标准的string类,加入集合中,集合会自动取消重复,并升序排列
    }
    copy(set1.begin(),set1.end(),ostream_iterator<string>(cout,"\n"));    //遍历输出集合
    return 0;
}

UVa 10815

原文:http://blog.csdn.net/jibancanyang/article/details/43528129

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!