fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var inputs = new List<string>();
  9. string read;
  10. do
  11. {
  12. read = Console.ReadLine();
  13. if(!string.IsNullOrWhiteSpace(read))
  14. {
  15. inputs.Add(read);
  16. }
  17. }while(!string.IsNullOrWhiteSpace(read));
  18.  
  19. for(int j = 0; j < inputs.Count; j++)
  20. {
  21. string input = inputs[j];
  22. string minimal = input;
  23. int index = 0;
  24. for(int i = 0; i < input.Length; i++)
  25. {
  26. var s1 = input.Substring(0,i);
  27. var s2 = input.Substring(i, input.Length - i);
  28. var s3 = s2 + s1;
  29.  
  30. if(s3.CompareTo(minimal) < 0)
  31. {
  32. minimal = s3;
  33. index = i;
  34. }
  35. }
  36.  
  37. Console.WriteLine($"{index} {minimal}");
  38. }
  39. }
  40. }
  41.  
Success #stdin #stdout 0.01s 132352KB
stdin
aabbccddbbaabb
onion
bbaaccaadd
alfalfa
weugweougewoiheew
pneumonoultramicroscopicsilicovolcanoconiosis
stdout
10 aabbaabbccddbb
2 ionon
2 aaccaaddbb
6 aalfalf
14 eewweugweougewoih
12 amicroscopicsilicovolcanoconiosispneumonoultr