James found his friend Harry's love letter for his girlfriend. James is very fond of pranks, so he decided to hook up. He converted every word in the letter into a reply. For any given string, it can reduce the value of any character. For example, 'D' can be changed to 'C', which is an operation. (In addition, he can only reduce the character value to 'A', and 'A' cannot be reduced to 'Z '). Find the minimum number of operations required to convert a given string to a forward object.
Input Format
The first line contains integers.TIndicates the number of groups of test data.
NextTEach row contains a string.
Output Format
Each row of test data is output, indicating the minimum number of operations required for this data.
Value Range
1 ≤T≤ 10
1 ≤String Length≤ 104
Question: a very simple question. At first, I thought about DFS =. =
To convert a string to a text return, the characters on I and l-I must be the same, so you only need to calculate all ABS (s [I]-s [L-I]). and.
1 import java.io.*; 2 import java.util.*; 3 import java.text.*; 4 import java.math.*; 5 import java.util.regex.*; 6 7 public class Solution { 8 static int The_Love_Letter_Mystery(String s){ 9 int sum = 0;10 if(s.length() <= 1)11 return 0;12 int start = 0;13 int end = s.length()-1;14 while(start<end){15 sum += Math.abs(s.charAt(start) - s.charAt(end));16 start++;17 end--;18 }19 return sum;20 }21 22 23 public static void main(String[] args) {24 Scanner in = new Scanner(System.in);25 int t = in.nextInt();26 for(int i = 0;i < t;i++){27 String string = in.next();28 System.out.println(The_Love_Letter_Mystery(string));29 }30 31 32 }33 }