fork(1) download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. void checkRepeatImpl(const char *word, uint64_t *tsar)
  5. {
  6. if (*word) {
  7. tsar[*word++]++;
  8. checkRepeatImpl(word, tsar); // Реку-ку-курсия. Хвостовая!
  9. }
  10. }
  11.  
  12. bool checkRepeatImpl(const uint64_t *tsar, size_t idx = 0)
  13. {
  14. return (idx < 256) && (tsar[idx] > 1 || checkRepeatImpl(tsar, idx + 1));
  15. }
  16.  
  17. bool checkRepeat(const char *word)
  18. {
  19. uint64_t tsar[256] = {};
  20. checkRepeatImpl(word, tsar);
  21. return checkRepeatImpl(tsar);
  22. }
  23.  
  24. int main()
  25. {
  26. std::cout << checkRepeat("") << std::endl // 0
  27. << checkRepeat("a") << std::endl // 0
  28. << checkRepeat("aa") << std::endl // 1
  29. << checkRepeat("abc") << std::endl // 0
  30. << checkRepeat("aaa") << std::endl // 1
  31. << checkRepeat("bab") << std::endl // 1
  32. << checkRepeat("baab") << std::endl // 1
  33. << checkRepeat("bbaaabb") << std::endl // 1
  34. << checkRepeat("bbabc") << std::endl // 1
  35. << checkRepeat("abcbb") << std::endl; // 1
  36.  
  37. return EXIT_SUCCESS;
  38. }
  39.  
Success #stdin #stdout 0s 4260KB
stdin
Standard input is empty
stdout
0
0
1
0
1
1
1
1
1
1