304 North Cardinal St.
Dorchester Center, MA 02124

# Minimum Absolute Score CodeChef Solution

## Minimum Absolute Score CodeChef Solution in C++17

``````#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
string a, b;
cin >> a >> b;
int sum = 0;
for (int i = 0; i < a.length(); i++)
{
if (a[i] < b[i])
{
sum = sum + b[i] - a[i];
}
else
{
sum = sum + 26 - (a[i] - b[i]);
}
}
int count = 0;
while (true)
{
if (26 * count >= sum)
{
break;
}
count++;
}
cout << abs(min(abs(sum - (count - 1) * 26), abs(sum - count * 26))) << endl;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}

return 0;
}``````

## Minimum Absolute Score CodeChef Solution in C++14

``````#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
string a, b;
cin >> a >> b;
int sum = 0;
for (int i = 0; i < a.length(); i++)
{
if (a[i] < b[i])
{
sum = sum + b[i] - a[i];
}
else
{
sum = sum + 26 - (a[i] - b[i]);
}
}
int count = 0;
while (true)
{
if (26 * count >= sum)
{
break;
}
count++;
}
cout << abs(min(abs(sum - (count - 1) * 26), abs(sum - count * 26))) << endl;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}

return 0;
}``````

## Minimum Absolute Score CodeChef Solution in PYTH 3

``````# cook your dish here

t=int(input())
for i in range(t):
n=int(input())
a=input()
b=input()
c=0
for i in range(n):
x=ord(a[i])-ord(b[i])
if x<=26:
c+=26
c+=x
print(min(26-c%26,c%26))``````

## Minimum Absolute Score CodeChef Solution in C

``````#include <stdio.h>

int main(void) {
int n,j,i,s;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d",&s);
char a[s+1];
char b[s+1];
scanf("%s",a);
scanf("%s",b);
int u[s],sum=0;
for(i=0;a[i]!='\0' || b[i]!='\0';i++)
{
if((a[i]-b[i])<0)
u[i]=26-abs(a[i]-b[i]);
else
u[i]=a[i]-b[i];
sum=sum+u[i];
}
int min=sum;
for(i=1;i<=s;i++)
{
if(abs(sum-(26*i)) < min)
min=abs(sum-(26*i));
}
printf("%d\n",min);
}
return 0;
}``````

## Minimum Absolute Score CodeChef Solution in JAVA

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
static class FastScanner {
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}

int ni() {
return Integer.parseInt(next());
}
int[] iArray0(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=ni();
return a;
}
int[] iArr1(int n){
int[] ar = new int[n + 1];
for(int i = 1; i <= n; i++) ar[i] = ni();
return ar;
}
long[] lArray0(int n){
long[] ar = new long[n];
for(int i = 0; i < n; i++) ar[i] = nl();
return ar;
}

long[] lArr1(int n){
long[] ar = new long[n + 1];
for(int i = 1; i <= n; i++) ar[i] = nl();
return ar;
}
long nl() {
return Long.parseLong(next());
}
}
static long mod=1000000007;
public static void main (String[] args) throws java.lang.Exception
{

FastScanner  sc = new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int tc = sc.ni();
for(int t=0; t<tc; t++){
// write code
int n= sc.ni();
String a= sc.next();
String b=sc.next();
///int ans=Integer.MAX_VALUE;
int cur=0;
for(int i=0; i<n; i++){
cur+=a.charAt(i)-b.charAt(i);
}
cur%=26;
int ans=Math.min((cur+26)%26,(26-cur)%26);
out.println(ans);
}
out.close();
}
// helper functions
//DisjointSet
static class DisjointSet{
int[] parent, rank;

DisjointSet(int n){
this.parent = new int[n];
this.rank = new int[n];
for(int i = 0; i < n; i++) this.parent[i] = i;
}

int find(int x){
if(x != parent[x]) parent[x] = find(parent[x]);
return parent[x];
}

boolean equiv(int x, int y){
return find(x) == find(y);
}

void union(int x, int y){
int xRoot = find(x), yRoot = find(y);

if(xRoot == yRoot) return;

if(rank[xRoot] < rank[yRoot]){
parent[xRoot] = yRoot;
}else if(rank[yRoot] < rank[xRoot]){
parent[yRoot] = xRoot;
}else{
parent[xRoot] = yRoot;
rank[yRoot]++;
}
}
}

public static int lower_bound(ArrayList<Integer> ar,int lo , int hi , int k)
{
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}

public static int upper_bound(ArrayList<Integer> ar,int lo , int hi, int k)
{
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <=k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}

static String  decimalToFraction(double number)
{

double intVal = Math.floor(number);
double fVal = number - intVal;
final long pVal = 1000000000;
long gcdVal = gcd(Math.round(
fVal * pVal), pVal);

long num = Math.round(fVal * pVal) / gcdVal;
long deno = pVal / gcdVal;
String ans= num+"/"+deno;
return ans;

}
static boolean isPrime(long N)
{
if (N<=1)  return false;
if (N<=3)  return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}

static  long pow(long a,long b)
{
long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}

static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

return ((1<<n)-1)^x;
}

static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}

static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}

private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
}``````

## Minimum Absolute Score CodeChef Solution in PYPY 3

``````for _ in range(int(input())):
n = int(input())
a = input()
b = input()
score = 0
for i in range(n):
if a[i]>b[i]:
up = 122-ord(a[i])+ord(b[i])-96
down = ord(a[i])-ord(b[i])
elif a[i]<b[i]:
up = ord(b[i])-ord(a[i])
down = 122-ord(b[i])+ord(a[i])-96
else:
continue
if abs(score+up)<abs(score-down):
score+=up
else:
score-=down
print(abs(score))``````

## Minimum Absolute Score CodeChef Solution in C#

``````using System;
using System.Linq;
using System.Globalization;

public class Test
{
private static int _mod = (int)1e9 + 7;

public static void Main(string[] args)
{
//Precompute();
int t = GetInt();
for (int i = 0; i < t; i++)
Solve();
}

public static void Solve()
{
int n = GetInt();
long ans = 0;
for(int i=0; i<n; i++)
{
ans += s[i] - t[i];
}
ans %= 26;
if(ans < 0)
ans += 26;

ans = Math.Min(ans, 26-ans);
#if DEBUG

#endif
Console.WriteLine(ans);
}

public static int GetInt() => int.Parse(Console.ReadLine());
public static long GetLong() => long.Parse(Console.ReadLine());

public static int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
public static long[] GetLongArray() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
public static double[] GetDoublesArray() => Console.ReadLine().Trim().Split(' ').Select(d => Convert.ToDouble(d, CultureInfo.InvariantCulture)).ToArray();

public static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
}``````

## Minimum Absolute Score CodeChef Solution in NODEJS

``````'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

return inputString[currentLine++];
}

function powerOfTwo(x) {
return Math.log2(x) % 1 === 0;
}

function mode(arr){
return arr.sort((a,b) =>
arr.filter(v => v===a).length
- arr.filter(v => v===b).length
).pop();
}

function main() {

let alphabetmap = {"a":1,
"b":2,
"c":3,
"d":4,
"e":5,
"f":6,
"g":7,
"h":8,
"i":9,
"j":10,
"k":11,
"l":12,
"m":13,
"n":14,
"o":15,
"p":16,
"q":17,
"r":18,
"s":19,
"t":20,
"u":21,
"v":22,
"w":23,
"x":24,
"y":25,
"z":26,}

loopwhile:
while(t--)
{

if(n!=arr1.length)
arr1.pop()
if(n!=arr2.length)
arr2.pop()

//console.log("arr1 " +arr2)
//console.log("arr2 " +arr1)

let diffsplus = []
let diffsminus = []
for(let i=0;i<n;++i)
{
if(alphabetmap[arr1[i]]<alphabetmap[arr2[i]])
{
diffsplus.push(alphabetmap[arr2[i]]-alphabetmap[arr1[i]])
diffsminus.push(26-Math.abs(alphabetmap[arr2[i]]-alphabetmap[arr1[i]]))
}
else
{
diffsplus.push(26-Math.abs(alphabetmap[arr2[i]]-alphabetmap[arr1[i]]))
diffsminus.push(alphabetmap[arr1[i]]-alphabetmap[arr2[i]])
}

}
//console.log("diffsplus:" + diffsplus)
//console.log("diffsminus:" + diffsminus)

let sum=0
for(let i=0;i<n;++i)
{
let summed1 = sum + diffsplus[i]
let summed2 = Math.abs(sum - diffsminus[i])
//console.log("summed1 :" + summed1)
//console.log("summed2 :" + summed2)
if(summed1 < summed2)
sum = summed1
else
sum-= diffsminus[i]
}
console.log(Math.abs(sum))
}
}``````

## Minimum Absolute Score CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"fmt"
"os"
)

func main() {

var buf bytes.Buffer

for tc > 0 {
tc--
res := solve(A[:n], B[:n])
buf.WriteString(fmt.Sprintf("%d\n", res))
}

fmt.Print(buf.String())
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

for i := 0; i < len(s); i++ {
if s[i] == '\n' || s[i] == '\r' {
return s[:i]
}
}
return s
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func solve(A, B string) int {
n := len(A)

// 先考虑一个slow的方案， 假设dp[x] = true , 表示能够活到差值为x的结果
// 对于i，要么right-shift A[i] d， dp[x+d] = true, 要们A[i] left-shift 26 - d, dp[x + 26 - d] = true
// 但这个太慢了。
var sum int

for i := 0; i < n; i++ {

if A[i] <= B[i] {
sum += int(B[i] - A[i])
} else {
sum += 26 - int(A[i]-B[i])
}

}
sum %= 26
return min(sum, 26-sum)
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}``````
##### Minimum Absolute Score CodeChef Solution Review:

In our experience, we suggest you solve this Minimum Absolute Score CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Minimum Absolute Score CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Minimum Absolute Score CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!