Problem Description
Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will get married next year.
But you turned on your computer and the operating system (OS) told you the HDD is about 95MB. The 5MB of space is missing. It is known that the HDD manufacturers have a different capacity measurement. The manufacturers think 1 “kilo” is 1000 but the OS thinks that is 1024. There are several descriptions of the size of an HDD. They are byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zetabyte and yottabyte. Each one equals a “kilo” of the previous one. For example 1 gigabyte is 1 “kilo” megabytes.
Now you know the size of a hard disk represented by manufacturers and you want to calculate the percentage of the “missing part”.
But you turned on your computer and the operating system (OS) told you the HDD is about 95MB. The 5MB of space is missing. It is known that the HDD manufacturers have a different capacity measurement. The manufacturers think 1 “kilo” is 1000 but the OS thinks that is 1024. There are several descriptions of the size of an HDD. They are byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zetabyte and yottabyte. Each one equals a “kilo” of the previous one. For example 1 gigabyte is 1 “kilo” megabytes.
Now you know the size of a hard disk represented by manufacturers and you want to calculate the percentage of the “missing part”.
Input
The first line contains an integer T, which indicates the number of test cases.
For each test case, there is one line contains a string in format “number[unit]” where number is a positive integer within [1, 1000] and unit is the description of size which could be “B”, “KB”, “MB”, “GB”, “TB”, “PB”, “EB”, “ZB”, “YB” in short respectively.
For each test case, there is one line contains a string in format “number[unit]” where number is a positive integer within [1, 1000] and unit is the description of size which could be “B”, “KB”, “MB”, “GB”, “TB”, “PB”, “EB”, “ZB”, “YB” in short respectively.
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1) and y is the percentage of the “missing part”. The answer should be rounded to two digits after the decimal point.
Sample Input
2 100[MB] 1[B]
Sample Output
Case #1: 4.63% Case #2: 0.00%
Hint
![](https://i-blog.csdnimg.cn/blog_migrate/e555a2c48911efce75497f333e6effb8.jpeg)
想法:快速幂
代码:
#include<stdio.h>
#include<string.h>
char a[100];
long long find(int x,int n)
{
long long a=x;
long long ans=1;
while(n)
{
if(n&1) ans=ans*a;
a=a*a;
n>>=1;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
int ws=1;
while(T--)
{
int n;
scanf("%d %s",&n,a);
//puts(a);
printf("Case #%d: ",ws++);
double ans;
if(strcmp(a,"[B]")==0)
{
printf("0.00%%\n");
}
else if(strcmp(a,"[KB]")==0)
{
ans=1.0*find(5,3)/find(2,7);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[MB]")==0)
{
//double aa=find(5,6);
//double bb=find(2,14);
//ans=aa/bb;
ans=1.0*find(5,6)/find(2,14);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[GB]")==0)
{
ans=1.0*find(5,9)/find(2,21);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[TB]")==0)
{
ans=1.0*find(5,12)/find(2,28);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[PB]")==0)
{
ans=1.0*find(5,15)/find(2,35);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[EB]")==0)
{
ans=1.0*find(5,18)/find(2,42);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[ZB]")==0)
{
//printf("%lld\n",find(5,21));
//printf("%lld\n",find(2,49));
ans=1.0*find(5,21)/find(2,49);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[YB]")==0)
{
//printf("%lld\n",find(5,24));
//printf("%lld\n",find(2,56));
ans=1.0*find(5,24)/find(2,56);
printf("%.2lf%%\n",(1-ans)*100);
}
}
return 0;
}
#include<string.h>
char a[100];
long long find(int x,int n)
{
long long a=x;
long long ans=1;
while(n)
{
if(n&1) ans=ans*a;
a=a*a;
n>>=1;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
int ws=1;
while(T--)
{
int n;
scanf("%d %s",&n,a);
//puts(a);
printf("Case #%d: ",ws++);
double ans;
if(strcmp(a,"[B]")==0)
{
printf("0.00%%\n");
}
else if(strcmp(a,"[KB]")==0)
{
ans=1.0*find(5,3)/find(2,7);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[MB]")==0)
{
//double aa=find(5,6);
//double bb=find(2,14);
//ans=aa/bb;
ans=1.0*find(5,6)/find(2,14);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[GB]")==0)
{
ans=1.0*find(5,9)/find(2,21);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[TB]")==0)
{
ans=1.0*find(5,12)/find(2,28);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[PB]")==0)
{
ans=1.0*find(5,15)/find(2,35);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[EB]")==0)
{
ans=1.0*find(5,18)/find(2,42);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[ZB]")==0)
{
//printf("%lld\n",find(5,21));
//printf("%lld\n",find(2,49));
ans=1.0*find(5,21)/find(2,49);
printf("%.2lf%%\n",(1-ans)*100);
}
else if(strcmp(a,"[YB]")==0)
{
//printf("%lld\n",find(5,24));
//printf("%lld\n",find(2,56));
ans=1.0*find(5,24)/find(2,56);
printf("%.2lf%%\n",(1-ans)*100);
}
}
return 0;
}