Skip to content

Instantly share code, notes, and snippets.

@TinfoilHat0
Created February 2, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TinfoilHat0/049433340abae54b5c1d to your computer and use it in GitHub Desktop.
Save TinfoilHat0/049433340abae54b5c1d to your computer and use it in GitHub Desktop.
#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