码迷,mamicode.com
首页 > 其他好文 > 详细

The Love-Letter Mystery

时间:2014-09-26 00:39:28      阅读:253      评论:0      收藏:0      [点我收藏+]

标签: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;
}


The Love-Letter Mystery

标签:the love-letter mystery

原文地址:http://9320314.blog.51cto.com/9310314/1558253

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!