fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<string> tks;
  5.  
  6. int main() {
  7. string sentence;
  8. getline(cin, sentence);
  9. istringstream iss(sentence);
  10. copy(istream_iterator<string>(iss),istream_iterator<string>(),back_inserter<vector<string>>(tks));
  11. set<string> s(tks.begin(),tks.end());
  12. cout<<"Number of distinct words are: "<<s.size()<<endl;
  13. for(auto it=s.begin();it!=s.end();it++){
  14. cout<<*it<<endl;
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 3240KB
stdin
hello world foo hello world bar
stdout
Number of distinct words are: 4
bar
foo
hello
world