码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 10815 安迪的第一个字典

时间:2016-08-12 01:26:16      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756

 

题意:很简单,把输入的文本,排序按字典序输出,相当于制作字典。

主要是set和stringstream的运用。

对于stringstream有个简单的程序。

 

#include<iostream>
#include<sstream>
using namespace std;

int main()
{
    string s = "12 3 4 5 6";
    cout<<s<<endl;
    int a = 1;
    stringstream os;
    os << s;        //以空格和回车键为分隔符
    while(os >> a)
        cout<<a<<endl;//输出12\n3\n4\n5\n6\n
    return 0;
}

 

 

 

#include<cstdio>
#include<iostream>
#include<set>
#include<sstream>
using namespace std;

set<string> dict;

int main()
{
    string s,buf;
    while(cin>>s){
        for(int i = 0;i < s.length(); i++)
            if(isalpha(s[i]))  s[i] = tolower(s[i]);
            else s[i] =  ;
        stringstream ss(s);
        while(ss >> buf) dict.insert(buf);      //分割s,插入set,按从小到大排列
    }
    //迭代器,认识较浅,记住格式
    for(set<string>::iterator it = dict.begin();it != dict.end(); ++it)
        cout<<*it<<"\n";
    return 0;
}

 

UVa 10815 安迪的第一个字典

标签:

原文地址:http://www.cnblogs.com/Since-natural-ran/p/5763310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!