Created
February 2, 2015 20:07
-
-
Save TinfoilHat0/049433340abae54b5c1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int palCount(string str){ | |
int i = 0, j = str.length() - 1, cnt = 0; | |
while(i < j){ | |
if (str[i] != str[j]) | |
cnt += abs(int(str[i]-str[j])); | |
i++; | |
j--; | |
} | |
return cnt; | |
} | |
int main() { | |
int t; | |
cin >> t; | |
string str; | |
while(t--){ | |
cin >> str; | |
cout << palCount(str) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment