# Cool Name | codechef solution

## Problem

Sardar Singh has many men fighting for him, and he would like to calculate the power of each of them to better plan for his fight against Ramadhir.

The power of a string $�$ of lowercase English alphabets is defined to be

$\sum _{�=1}^{\mathrm{\mid }�\mathrm{\mid }}�\cdot ���\left({�}_{�}\right)$

where $���\left({�}_{�}\right)$ is the position of ${�}_{�}$ in the alphabet, i.e, $���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)=1,���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)=2,\dots ,���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)=26$.

Each of Sardar Singh's men has a name consisting of lowercase English alphabets. The power of a man is defined to be the maximum power over all possible rearrangements of this string.

Find the power of each of Sardar Singh's men.

### Input Format

• The first line of input contains an integer $�$, denoting the total number of Sardar Singh's men.
• Each of the next $�$ lines contains a single string ${�}_{�}$, the name of Sardar Singh's $�$-th man.

### Output Format

• Output $�$ lines, each containing a single integer. The $�$-th of these lines should have the power of the $�$-th of Sardar Singh's men.

### Constraints

• $1\le �\le 60$
• $1\le \mathrm{\mid }{�}_{�}\mathrm{\mid }\le 100$
• ${�}_{�}$ consists of lowercase english alphabets only.

Input
Output
1
faizal
273

### Explanation:

The rearrangement with maximum power is $������$. Its power can be calculated as

$1\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)+2\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)+3\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)+4\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)+5\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)+6\cdot ���{\left(}^{\mathrm{\prime }}{�}^{\mathrm{\prime }}\right)$

which equals $273$. It can be verified that no rearrangement gives a larger power.

Code(C++):-

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
sort(s.begin(),s.end());
int ans=0;
for(int i=0;s[i];i++)
{
int a=s[i]-96;
ans+=((i+1)*a);
}
cout<<ans<<endl;

}
return 0;
}

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-