zoukankan      html  css  js  c++  java
  • Problem C Andy's First Dictionary(set的使用)

    题目链接:Problem C

    题意:输入一个文本,找出所有不同的单词,按照字典序从小到大输出,单词不区分大小写。

    思路:将字母序列都存为小写,非字母的字符变成空格,然后利用stringstream实现sting对象的自动格式化。

    note: 
    stringstream对象的使用 #include
    <sstream> #include<iostream> using namespace std; int main() { string line,word; while(getline(cin,line)) { stringstream stream(line); cout<<stream.str()<<endl; while(stream>>word){cout<<word<<endl;} } return 0; } /* * input: shanghai no1 school 1989 * output: shanghi no1 school 1989 * shanghai * no1 * school * 1989 */

    code:

     1 #include <iostream>
     2 #include <string>
     3 #include <set>
     4 #include <sstream>
     5 #include <cctype>
     6 using namespace std;
     7 set<string> dirt;
     8 int main()
     9 {
    10     string str, word;
    11     dirt.clear();
    12     while (cin >> str)
    13     {
    14         int len = str.size();
    15         for (int i = 0; i < len; ++i)
    16         {
    17             if (isalpha(str[i])) str[i] = tolower(str[i]);
    18             else str[i] = ' ';
    19         }
    20         stringstream buf(str);
    21         while (buf >> word) dirt.insert(word);
    22     }
    23     set<string>::iterator it;
    24     for (it = dirt.begin(); it != dirt.end(); ++it)
    25         cout << *it << endl;
    26     return 0;
    27 }
  • 相关阅读:
    purple-class2-默认选项切换
    purple-accessData
    “/wechat”应用程序中的服务器错误。
    GDI+ 中发生一般性错误。
    ylbtech-Unitity-CS:Indexers
    ylbtech-Unitity-CS:Hello world
    ylbtech-Unitity-CS:Generics
    ylbtech-Unitity-CS:Delegates
    ZooKeeper目录
    Zookeeper常用命令 (转)
  • 原文地址:https://www.cnblogs.com/ykzou/p/4610725.html
Copyright © 2011-2022 走看看