The Love-Letter Mystery
#include<cmath>
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
int T;
cin>>T;
string str;
getline(cin,str);
while(T--)
{
string str1;
int count;
getline(cin,str1);
count = str1.length() ;
int sum = 0,n = 0;
int j = count/2;
for(int i = 0;i < j ;i++)
{
if(static_cast<int>(str1[count - 1 - i]) >= static_cast<int>(str1[0 + i]))
{
n = static_cast<int>(str1[count - 1 - i] - str1[0 + i]);
sum += n;
}
else
{
n = static_cast<int>(str1[0 + i]) - static_cast<int>(str1[count - 1 - i]);
sum += n;
}
}
cout<<sum<<endl;
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
转载于:https://blog.51cto.com/9320314/1558253