zoukankan      html  css  js  c++  java
  • 水题(细节考察getline) 之 hdu 2072

    //  [7/23/2014 Sjm]
    /*
    细节考察:
    WA了几次。。。由于空格可以被 getline 读入,所以增加判断条件。。。
    测试用例:
     ab (注意ab前有一个空格)
    输出:
    1
    */
     1 #include <iostream>
     2 #include <cstdlib>
     3 #include <cstdio>
     4 #include <string>
     5 #include <set>
     6 using namespace std;
     7 
     8 bool Judge(char ch) {
     9     if (ch >= 'a' && ch <= 'z') {
    10         return true;
    11     }
    12     return false;
    13 }
    14 
    15 int main()
    16 {
    17     //freopen("input.txt", "r", stdin);
    18     string str;
    19     while (getline(cin, str) && str != "#") {
    20         str += ".";
    21         string t_str;
    22         set<string> myset;
    23         for (int i = 0; i < str.size(); ++i) {
    24             if (Judge(str[i])) {
    25                 t_str += str[i];
    26             }else {
    27                 if (t_str.size()) { // 此处增加判断条件
    28                     myset.insert(t_str);
    29                 }
    30                 t_str = "";
    31             }
    32         }
    33         cout << myset.size() << endl;
    34         myset.clear();
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    Go语言标准库flag基本使用
    GO学习-(12) Go语言基础之函数
    GO学习-(11) Go语言基础之map
    GO学习-(10) Go语言基础之指针
    Spring AOP
    JDK动态代理
    版本控制
    版本控制
    浅析Java反射机制
    Spring Batch学习
  • 原文地址:https://www.cnblogs.com/shijianming/p/4140821.html
Copyright © 2011-2022 走看看