1. 程式人生 > >uva 10815,andy's first ditionary(set,stringstream的簡單運用)

uva 10815,andy's first ditionary(set,stringstream的簡單運用)

dtw spa alpha else 運用 大小寫 不同的 ngs 簡單

題意:輸入一個文本,找出所有不同的單詞,按字典序從小到大輸出。單詞不區分大小寫。

樣例輸入:

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

樣例輸出:

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
8O
the
they
to
two
went
were
when

代碼如下:

#include<set>
#include<iostream>
#include<sstream>
#include<string>
#include<cstring>
using namespace std;
 int main(int argc, char const *argv[]) {
  string s,temp;
  set<string>dict;
  set<string>::iterator it;
  stringstream ss;
  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>>temp){ dict.insert(temp);//將轉換後的單詞輸入set } } for(it=dict.begin();it!=dict.end();it++){ std::cout
<< *it << \n;//按字典序輸出 } return 0; }



uva 10815,andy's first ditionary(set,stringstream的簡單運用)