fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main(int argc, char** argv) {
  5. std::vector<std::string> strings = {"onion", "bbaaccaadd", "alfalfa", "weugweougewoiheew", "pneumonoultramicroscopicsilicovolcanoconiosis"};
  6.  
  7. for (auto& str : strings) {
  8. std::string lowestRot = str;
  9. unsigned int sizeOfRot = 0;
  10.  
  11. for (auto it = str.begin(); it != str.end(); it++) {
  12. std::string rotated {it, str.end()};
  13.  
  14. rotated += std::string {str.begin(), it};
  15. if (rotated < lowestRot) {
  16. lowestRot = rotated;
  17. sizeOfRot = std::distance(str.begin(), it);
  18. }
  19. }
  20.  
  21. std::cout << sizeOfRot << " " << lowestRot << std::endl;
  22.  
  23. }
  24. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
2 ionon
2 aaccaaddbb
6 aalfalf
14 eewweugweougewoih
12 amicroscopicsilicovolcanoconiosispneumonoultr