fork download
  1. #include <iostream>
  2.  
  3. char foo(const std::string& s, std::size_t index)
  4. {
  5. auto size = s.size();
  6.  
  7. while (size <= index) {
  8. size *= 2;
  9. }
  10. while (size != s.size()) {
  11. size /= 2;
  12. if (index >= size) {
  13. index = (index - 1) % size;
  14. }
  15. }
  16. return s[index];
  17. }
  18.  
  19. int main()
  20. {
  21. for (int i = 0; i != 12; ++i) {
  22. std::cout << foo("COW", i);
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
COWWCOOCOWWC