fork(1) download
  1.  
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. struct dict
  7. {
  8. std::string word;
  9. };
  10.  
  11. bool exists(const dict* words, size_t count, const std::string& check)
  12. {
  13. for(size_t n = 0; words && (n < count); ++n)
  14. {
  15. if(words[n].word == check)
  16. return true;
  17. }
  18.  
  19. return false;
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25. dict langs[3];
  26.  
  27. langs[0].word = "C++";
  28. langs[1].word = "Java";
  29. langs[2].word = "Python";
  30.  
  31. std::string s_1 = "Java";
  32. std::string s_2 = "C++ 11";
  33.  
  34. printf("exists(%s) : %s\n", s_1.c_str(), exists(langs, 3, s_1) ? "yes" : "no");
  35. printf("exists(%s) : %s\n", s_2.c_str(), exists(langs, 3, s_2) ? "yes" : "no");
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
exists(Java) : yes
exists(C++ 11) : no