[hackerrank]The Love-Letter Mystery

https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery

简单题。

#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	while (N--) {
		string s;
		cin >> s;
		int count = 0;
		int l = 0;
		int r = s.size() - 1;
		while (l < r) {
			count += abs(s[l++] - s[r--]);
		}
		cout << count << endl;
	}
    return 0;
}

  

posted @ 2014-08-14 15:46  阿牧遥  阅读(198)  评论(0编辑  收藏  举报