UVa10815,Andy's First Dictionary, set,stringstream

题意:

输入一个文本,找出所有不同的单词,按字典序输出所有单词。

stringstream通常是用来做数据转换的

相比c库的转换,它更加安全,自动和直接

#include <sstream>

stringstream stream

stream <<value   输入

stream >>value   读取

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

set<string> dict;

int main()
{
    string s, buf;
    while(cin>>s){
        for(int i=0; i<s.size(); ++i){
            if(isalpha(s[i])) s[i] = tolower(s[i]);
            else s[i] = ' ';
        }
        stringstream stream;
        stream.clear();
        stream<<s;
        while(stream>>buf) dict.insert(buf);
    }
    for(set<string>::iterator it =dict.begin(); it!=dict.end(); ++it)
        cout<<*it<<endl;
    return 0;
}

UVa10815,Andy's First Dictionary, set,stringstream

时间: 2024-08-11 07:21:41

UVa10815,Andy's First Dictionary, set,stringstream的相关文章

UVa10815 Andy&#39;s First Dictionary (STL)

链接:http://acm.hust.edu.cn/vjudge/problem/18649分析:set容器应用.set中每个元素最多只出现一次.自定义类型也可以构造set,必须定义“小于”运算符.set中的元素从小到大已排好序. 1 #include <iostream> 2 #include <string> 3 #include <cctype> 4 #include <set> 5 #include <sstream> 6 using n

UVA10815 Andy&#39;s First Dictionary

问题链接:UVA10815 Andy's First Dictionary. 题意简述:输入一个文本文件,从中提取出字典,重复的单词被去掉. 这个问题用C++语言编写程序,主要是为了练习使用STL的功能.另外一点,C++编写程序效率会更高. 使用STL容器类的set,可以方便地去重复,而且还会自动排序. 程序中,使用C语言的库函数strtok()来切割单词,并且用空格' '作为分隔符.这是一种简便的做法. 另外一种切割字符串的方法是,使用STL的字符串流(sstream)实现. AC的C++程序

C# 谈Dictionary&lt;TKey,TValue&gt;,SortedDictionary&lt;TKey,TValue&gt;排序

使用过Dictionary的人都知道,当每一个Add里面的值都不会改变其顺序,所以需要需要对其排序的时候就用到SortedDictionary, 但SortedDictionary并不是那么理想,其默认的方式只支持正序排序,想要反序排序时必须得靠自己重新编写代码,下面来看一个简单的例子: private void TestDictionarySort() { SortedDictionary<string, string> sd = new SortedDictionary<string

【UVA】12504 - Updating a Dictionary(map,string,vector模拟)

一般的模拟题,一开始WA,可能是用string的容器放char,改成string就过了 14073581 12504 Updating a Dictionary Accepted C++ 0.032 2014-08-21 07:12:19 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<st

[WinForm] DataGridView绑定DataTable,ComboBox列绑定Dictionary

一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面上我们想要显示的是具体的文本内容,以便用户理解使用.所以在从数据库中加载出来的数据DataTable绑定到DataGridView上时,就需要其中一些枚举列采用下拉框,并绑定对应的枚举数据源. 二  具体实现 首先,如果 DataGridView 的 AutoGenerateColumns 为 true 时,

安迪的第一个字典 (Andy&#39;s First Dictionary,UVa10815)

题目描述: #include<iostream> #include<string> #include<set> #include<sstream> using namespace std; set<string> dic; string s, buf; int main() { while(cin >> s) { for(int i = 0; i < s.length(); i++) if(isalpha(s[i])) s[i]

【UVA - 10815】Andy&#39;s First Dictionary (set)

Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英语.于是他每天都读一篇只包含生词的英语文章,并以自己高达450的智商在一秒钟之内记忆下来. 现在给你一篇XY学长今天要读的文章,请你写一个程序,输出他都学习到了哪些单词.要求:如果文章中有相同的单词,那么仅仅输出一次:而且如果两个单词只有大小写不同,将他们视为相同的单词. Input 测试数据将输入

Winter-2-STL-E Andy&#39;s First Dictionary 解题报告及测试数据

use stringstream Time Limit:3000MS     Memory Limit:0KB Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thin

UVa - 10815 Andy&#39;s First Dictionary(STL)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18649 #include <iostream> #include <string> #include <set> #include <sstream> using namespace std; /******************************************************************