The Love-Letter Mystery

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章