fork download
  1. import std.stdio;
  2. import std.typecons : tuple;
  3. import std.string : strip;
  4.  
  5. void main()
  6. {
  7. foreach(line; stdin.byLine)
  8. {
  9. auto word = line.strip;
  10. auto current = word.dup;
  11. auto smallest = tuple(0, current);
  12. int rotations;
  13. do
  14. {
  15. current = current[1 .. $] ~ current[0];
  16. rotations++;
  17. if(current < smallest[1])
  18. {
  19. smallest[0] = rotations;
  20. smallest[1] = current;
  21. }
  22. }
  23. while(current != word);
  24. writeln(smallest[0], ' ', smallest[1]);
  25. }
  26. }
Success #stdin #stdout 0s 14976KB
stdin
aabbccddbbaabb
onion
bbaaccaadd
alfalfa
weugweougewoiheew
pneumonoultramicroscopicsilicovolcanoconiosis
stdout
10 aabbaabbccddbb
2 ionon
2 aaccaaddbb
6 aalfalf
14 eewweugweougewoih
12 amicroscopicsilicovolcanoconiosispneumonoultr