zoukankan      html  css  js  c++  java
  • UVA 10815 Andy's First Dictionary【set】

    题目链接:https://vjudge.net/contest/211547#problem/C

    题目大意:

    输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写。

    Sample Input

    Adventures in Disneyland Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left." So they went home.

    Sample Output

    a

    adventures

    blondes

    came

    disneyland

    ……

    #include<iostream>
    #include<string>
    #include<set>
    #include<sstream>
    using namespace std;
    
    set<string> dict;
    string s, buf;
    
    int main() {
      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);         //将字符串流中的单词一个一个的存储在集合内
      }
      for(set<string>::iterator it = dict.begin(); it != dict.end(); ++it)                //set具有给集合内元素去重和自动排序的功能
        cout << *it << "
    ";
      return 0;
    }

    2018-04-05


    作者:is_ok
    出处:http://www.cnblogs.com/00isok/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    将字符数组写到字符串
    两种比较不错的密码修改方案
    数组的应用 结构类型 使用深复制和浅复制 显示员工信息
    字符串处理技巧
    uva 1339
    11039
    uva 11636
    Uva401Palindromes
    poj2524-Ubiquitous Religions
    Poj1611The Suspects
  • 原文地址:https://www.cnblogs.com/00isok/p/8722099.html
Copyright © 2011-2022 走看看