-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrectnessAndTheLoopInvariant.js
74 lines (60 loc) · 1.44 KB
/
correctnessAndTheLoopInvariant.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k;
String a[]=new String[20];
for(k=0;k<=n;k++)
a[k]=sc.nextLine();
for(k=1;k<=n;k++)
{
int count=0;
int i=0;
int len=a[k].length();
int j=len-1;
while(i<j)
{
int i1=(int)a[k].charAt(i);
int j1=(int)a[k].charAt(j);
if(i1==j1)
{
}
if(i1>j1)
{
count=count+(i1-j1);
}
if(i1<j1)
{
count=count+(j1-i1);
}
i++;
j--;
}
System.out.println(count);
}
}
}
function insertionSort (ar) {
return ar.sort(function(a,b){return a - b}).join(" ");
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
//get input for ar
_input = _input.split("\n");
_input.shift();
_input = _input[0].split(" ");
var a = insertionSort(_input);
//print ar
console.log(a);
});