fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. bool existWord(vector<string> word_list, string word)
  10. {
  11. vector<string>:: iterator it;
  12.  
  13. it= find(word_list.begin(), word_list.end(), word);
  14. if(it== word_list.end())
  15. return 0;
  16. else
  17. return 1;
  18. }
  19. int main() {
  20.  
  21. vector<string > word_list(3);
  22.  
  23. word_list[0]= "hello";
  24. word_list[1]= "world";
  25. word_list[2]= "working";
  26.  
  27. cout<< existWord(word_list, "hi")<< endl;
  28. cout<< existWord(word_list, "hello")<< endl;
  29. cout<< existWord(word_list, "world")<< endl;
  30. cout<< existWord(word_list, "work")<< endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
0
1
1
0