-->
当前位置:首页 > 题库

PROGRAMMING:String number problem

Luz5年前 (2021-05-10)题库415
String number problem: character a or a corresponds to 1, B or B-2, C-3,..., Z or z-26, aa-27, ab-28, ac-29,..., ba-53, bb-54,..., and so on
It is required to input a string of up to 10 letters and output its corresponding decimal double precision value according to the above corresponding relationship.
###Input format:
Enter a string of 26 uppercase or lowercase letters on one line: for example, ABC
###Output format:
Output string corresponding to the decimal double precision value, retain two decimal places: such as 731.00
###Input sample 1:
```in
aBc
```
###Output sample 1:
```out
seven hundred and thirty-one
```
###Input sample 2:
```in
abcdefghij
```
###Output sample 2:
```out
five trillion and eight hundred and seventy-two billion five hundred and fifty-one million one hundred and seventy-nine thousand one hundred and eighty
```







answer:If there is no answer, please comment
```
//String number problem, A-1, B-2, C-3,.... z-26, aa-27, bb-28
#include
#include
int main()
{
char str[10],c;
int i,j;
double num;
scanf("%s",str);
num=0;
for(i=0; i{
c=str[i];
if (c>='a'&&c<='z') j=c-97+1;// Handle lowercase letters, corresponding to numbers 1-26
else if(c>='A'&&c<='Z') j=c-65+1;// Handle large letters, corresponding to numbers 1-26
else {printf("ERROR"); return 0;}
num=num*26+j;// For example, aa-27, ab-28,..., fbxcadf-1888278346
}
printf("%0.2lf\n",num);
return 0;
}
```