程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> HDU2072 單詞數

HDU2072 單詞數

編輯:關於C++

單詞數

Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40427Accepted Submission(s): 9719

Problem Description lily的好朋友xiaoou333最近很空,他想了一件沒有什麼意義的事情,就是統計一篇文章裡不同單詞的總數。下面你的任務是幫助xiaoou333解決這個問題。
Input 有多組數據,每組一行,每組就是一篇小文章。每篇小文章都是由小寫字母和空格組成,沒有標點符號,遇到#時表示輸入結束。
Output 每組只輸出一個整數,其單獨成行,該整數代表一篇文章裡不同單詞的總數。
Sample Input

you are my friend #

Sample Output

4

Author Lily

分析:恩,的確是的水題,直接暴力就行。但是,我發現了一個更牛逼的寫法,一個超級牛逼的東西stream,這東西是真的屌爆了。不吹了,看代碼。
<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define MAXN 100010
#include <sstream>

set<string> temp;
string row,input;
int main()
{
    while(getline(cin, row)&&row!="#")///輸入一行字符串可以用getline
    {
        temp.clear();
        stringstream str(row);
        while(str>>input)
            temp.insert(input);
        cout<<temp.size()<<endl; return="" span=""></temp.size()<<endl;></string></sstream></algorithm></cmath></vector></set></map></queue></stack></cstring></cstdio></iostream></span>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved