2015
09-18

# Hard Disk Drive

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”.

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.

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.

2
100[MB]
1[B]

Case #1: 4.63%
Case #2: 0.00%

Hint



AC代码：

#include<stdio.h>
#include<math.h>
int main() {
int a, n, m = 0;
double d = 1000;
char s[10], ch;
for(int i = 1; i <= 10; i++)
d /= 2;
int t;
scanf("%d", &t);
while(t--) {
scanf("%s", s);
n = 0;
for(int i = 0; s[i]; i++) {
if(s[i] >= '0' && s[i] <= '9')
n = n * 10 + s[i] - '0';
else {
if(s[i] == '[')
continue;
ch = s[i];
break;
}
}
printf("Case #%d: ", ++m);
if(ch == 'B') printf("%.2f%%\n", (1 - pow(d, 0)) * 100);
if(ch == 'K') printf("%.2f%%\n", (1 - pow(d, 1)) * 100);
if(ch == 'M') printf("%.2f%%\n", (1 - pow(d, 2)) * 100);
if(ch == 'G') printf("%.2f%%\n", (1 - pow(d, 3)) * 100);
if(ch == 'T') printf("%.2f%%\n", (1 - pow(d, 4)) * 100);
if(ch == 'P') printf("%.2f%%\n", (1 - pow(d, 5)) * 100);
if(ch == 'E') printf("%.2f%%\n", (1 - pow(d, 6)) * 100);
if(ch == 'Z') printf("%.2f%%\n", (1 - pow(d, 7)) * 100);
if(ch == 'Y') printf("%.2f%%\n", (1 - pow(d, 8)) * 100);
}
return 0;
}