天天看點

ACM-水題之Hard Disk Drive——HDU4788Hard Disk Drive

Hard Disk Drive

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

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.  

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%


  這道題是成都現場賽重放的,額。。怎麼說呢,特别水的一道題把。。。
題意大概就是:計算機專業的人知道容量之間的轉換是1024即2^10,而非計算機專業的認為是1000即10^3,
假設,我們按10^3算,那麼和原來按2^10的比,差了總量的百分之多少?
當然容量不可能隻有KB到B之間的轉換還有MB GM TB PB EB ZB YB。

系數基本上就不用管了,答案肯定是  1-(系數*10^3*相應轉換的階級)/(系數*2^10*相應階級)
是以系數就會約去,然後差一個階級就是差一個 1000/1024,


代碼:

         
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;

int main()
{
    int t,mem,jie;
    int i;
    double a,arr[10];
    string str;

    for(i=1;i<=8;++i)
    {
        a=1000.0/1024;
        arr[i]=(1-pow(a,i))*100;
    }

    scanf("%d",&t);
    for(i=1;i<=t;++i)
    {
        cin>>mem>>str;

        if(str[1]=='B') jie=0;
        else if(str[1]=='K') jie=1;
        else if(str[1]=='M') jie=2;
        else if(str[1]=='G') jie=3;
        else if(str[1]=='T') jie=4;
        else if(str[1]=='P') jie=5;
        else if(str[1]=='E') jie=6;
        else if(str[1]=='Z') jie=7;
        else jie=8;
        
        if(jie==0)
        {
            printf("Case #%d: %.2f%%\n",i,mem);
            continue;
        }

        printf("Case #%d: %.2f%%\n",i,arr[jie]);
        
    }
    return 0;
}