Advertisement
royalsflush

Referência para High Score (LA 4946)

Jul 3rd, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int _42;
  7. char s[1010]; int l;
  8. int change;
  9. int mvs;
  10.  
  11. int minMoves(int idx) {
  12.     int notA;
  13.  
  14.     for (notA=idx+1; s[notA]!='\0'; notA++)
  15.         if (s[notA]!='A')
  16.             break;
  17.  
  18.     return 2*min(idx,l-notA)+max(idx,l-notA);
  19. }
  20.  
  21. int main() {
  22.     scanf("%d", &_42);
  23.  
  24.     while (_42--) {
  25.         scanf(" %s", s);
  26.         change=0;
  27.  
  28.         for (l=0; s[l]!='\0'; l++)
  29.             change+=min(s[l]-'A', 26-s[l]+'A');
  30.  
  31.         mvs=200000;
  32.         for (int i=0; s[i]!='\0'; i++)
  33.             mvs=min(mvs,minMoves(i));
  34.  
  35.         printf("%d\n", change+mvs);
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement