Problem link:CodeChef: Practical coding for everyone
Setter:Ankur Pandey
Tester:Ankur Pandey
Difficulty:
easy
Time Complexity:O(n)
Problem:…
Explanation:It is given that all alphabetical are arranged in a row starting from
index 0
So the logic can be framed as
A=27(given) if we subtract 27-0(index of A i.e 0)we get 27
Similarly
AND
A=27-0=27
N=27-13=14
D=27-3=24
so, 27+14+24=65
#include<bits/stdc++.h>
using namespace std;
int main()
{
char arr[100];
cin>>arr;
int l= strlen(arr);
int sum=0;
for (int i = 0; i < l; i++)
{
int diff=abs(arr[i]-‘A’);
sum+=abs(27-diff);
}
cout<<sum<<endl;
}