hdu 2072

一道簡單題目,不過直接用字符統計  還是比較麻煩的,用set比較適合解決這個問題,
另外輸入處理也有個小技巧  使用 stringstream保存一行文本會方便很多,最後一點 在每個測試用例結束不要忘了給
set清空

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

set<string> S;
int main()
{
    string row,input;
 while(getline(cin,row)&&row!="#")
 {
  S.clear();
  stringstream str(row);
  while(str>>input)S.insert(input);
     cout<<S.size()<<endl;
 } 
    return 0;
}

發佈了39 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章