読者です 読者をやめる 読者になる 読者になる

SRM158 div2

#EASY

  1 public class TireRotation {
  2     String rot(String before) {
  3         String after = "";
  4         after += before.charAt(3);
  5         after += before.charAt(2);
  6         after += before.charAt(0);
  7         after += before.charAt(1);
  8         return after;
  9     }
 10
 11     public int getCycle(String initial, String current) {
 12         for(int i=1;i<5;i++) {
 13             if(initial.equals(current))
 14                 return i;
 15             initial = rot(initial);
 16         }
 17         return -1;
 18     }

© karahiyo