hdu 2072 单词数
生活随笔
收集整理的這篇文章主要介紹了
hdu 2072 单词数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://acm.hdu.edu.cn/showproblem.php?pid=2072
?
單詞數(shù)這道題感覺用c寫很麻煩,用c++寫就比較簡單了。不多說,直接貼代碼。
#include<iostream> #include<string> #include<vector> #include<sstream>using namespace std;int main() {vector<string> s;string s0,s1;int flag;while(getline(cin,s0)){if(s0=="#")break;else{s.clear();istringstream sin(s0);while(sin>>s1){flag=0;for(int i=0;i<s.size();i++){if(s[i]==s1){flag=1;break;}}if(flag==0)s.push_back(s1);}cout<<s.size()<<endl;}}return 0; }感覺用set更簡單,這是網(wǎng)上的代碼:
#include <iostream> #include <set> #include <string> #include <sstream>// 不要忘記了 using namespace std; int main() { string art; while(getline(cin,art) && art != "#"){ istringstream stream(art); string word; set<string> map; while(stream >>word){ map.insert(word); } cout <<map.size() <<endl; } return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/yaoyueduzhen/p/4336104.html
總結(jié)
以上是生活随笔為你收集整理的hdu 2072 单词数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 火狐浏览器刷新ctrl+F5
- 下一篇: 苹果开发信息 审核