fork(1) download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. bool cr(const char *p, char *c) {
  5. return c[*p] || *p && ++c[*p] && cr(p + 1, c);
  6. }
  7.  
  8. bool checkRepeat(const char *word)
  9. {
  10. char cache[256] {};
  11. return cr(word, cache);
  12. }
  13.  
  14. int main()
  15. {
  16. std::cout << checkRepeat("") << std::endl // 0
  17. << checkRepeat("a") << std::endl // 0
  18. << checkRepeat("aa") << std::endl // 1
  19. << checkRepeat("abc") << std::endl // 0
  20. << checkRepeat("aaa") << std::endl // 1
  21. << checkRepeat("bab") << std::endl // 1
  22. << checkRepeat("baab") << std::endl // 1
  23. << checkRepeat("bbaaabb") << std::endl // 1
  24. << checkRepeat("bbabc") << std::endl // 1
  25. << checkRepeat("abcbb") << std::endl; // 1
  26.  
  27. return EXIT_SUCCESS;
  28. }
  29.  
Success #stdin #stdout 0s 4544KB
stdin
Standard input is empty
stdout
0
0
1
0
1
1
1
1
1
1