SHARE
TWEET

Referência para High Score (LA 4946)

royalsflush Jul 3rd, 2012 1 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top