-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (28 loc) · 784 Bytes
/
Solution.java
File metadata and controls
33 lines (28 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int theLoveLetterMystery(String s){
int counter = 0;
int i = 0;
int j = s.length() - 1;
while (i <= j) {
if (s.charAt(i) != s.charAt(j)) {
counter += Math.abs(((int) s.charAt(i)) - ((int) s.charAt(j)));
}
i++; j--;
}
return counter;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++){
String s = in.next();
int result = theLoveLetterMystery(s);
System.out.println(result);
}
}
}