EASY WAY TO SOLVE THIS QUESTION:
To output the given number for the given input which is a string (not case sensitive).
Input : B
Output : 2
To output the given number for the given input which is a string (not case sensitive).
Input : B
Output : 2
Input Format
The first line has an integer T. T testcases follow.
The next T lines follow a string S on each line.
The next T lines follow a string S on each line.
Constraints
Length(S)>0
Output Format
Print the sequence number.
Sample Input
3
ac
Ab
ALL
ac
Ab
ALL
Sample Output
29
28
1000
28
1000
Explanation:
For example ,we take excel sheet every column should named with alphabets.First column named with 'A',Second column named with 'B'.....26 th column as 'Z'. After finishing 26 alphabets,27th column as 'AA',28th column as 'AB' as like it's going....
you should display the column number for the column name in excel sheet.
One of these method to approach this question:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
char str[100];
int t,i,len,sum=0;
scanf("%d",&t);
while(t--)
{
//gets(str);
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
sum=sum*26+(toupper(str[i])-'A')+1;
}
printf("%d\n",sum);
sum=0;
}
}
For example ,we take excel sheet every column should named with alphabets.First column named with 'A',Second column named with 'B'.....26 th column as 'Z'. After finishing 26 alphabets,27th column as 'AA',28th column as 'AB' as like it's going....
you should display the column number for the column name in excel sheet.
One of these method to approach this question:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
char str[100];
int t,i,len,sum=0;
scanf("%d",&t);
while(t--)
{
//gets(str);
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
sum=sum*26+(toupper(str[i])-'A')+1;
}
printf("%d\n",sum);
sum=0;
}
}
No comments:
Post a Comment