fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. bool contains(int i_find, std::vector<int> list)
  6. {
  7. return list.empty() ? false : (*list.begin() == i_find ? true : contains(i_find, {list.begin()+1, list.end()}));
  8. }
  9.  
  10. int main() {
  11. printf("contains 0: %i\n", contains(0, {1,2,3,4}) ? 1 : 0);
  12. printf("contains 1: %i\n", contains(1, {1,2,3,4}) ? 1 : 0);
  13. printf("contains 2: %i\n", contains(2, {1,2,3,4}) ? 1 : 0);
  14. printf("contains 3: %i\n", contains(3, {1,2,3,4}) ? 1 : 0);
  15. printf("contains 4: %i\n", contains(4, {1,2,3,4}) ? 1 : 0);
  16. printf("contains 5: %i\n", contains(5, {1,2,3,4}) ? 1 : 0);
  17. // your code goes here
  18. return 0;
  19. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
contains 0: 0
contains 1: 1
contains 2: 1
contains 3: 1
contains 4: 1
contains 5: 0