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

}

  

你可能感兴趣的:(rank)