HDU 4788 Hard Disk Drive

本文介绍了一个简单的程序,用于计算硬盘制造商所标示的容量与操作系统实际显示容量之间的百分比差异。通过解析输入字符串中的数值与单位,程序可以处理从字节到尧字节等不同单位,并输出每种情况下的“缺失部分”百分比。

Hard Disk Drive

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 125    Accepted Submission(s): 75

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%
Hint
 
 
Source
 
Recommend
We have carefully selected several similar problems for you:   4790  4789  4787  4786  4785 
 
思路:水题
 
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
int t;
int the_number;
double sum;
int the_flag;
double the_result;
char map[10];
char str;
int main()
{
    scanf("%d",&t);
    for(int k = 1;k <= t;k ++)
    {
        memset(map,0,sizeof(map));
        the_flag = 0;
        the_number = 0;
        sum = 1;
        the_result = 0;
        scanf("%s",map);
        int m = 1;
        for(int i = 0;i < 10;i ++)
        {
            if(map[i] == '[')
            {
                str = map[i + 1];
                break ;
            }
            the_number = the_number * m + map[i] - '0';
            m = 10;
        }
        printf("Case #%d: ",k);
        if(str == 'B')
           the_flag = 0;
        if(str == 'K')
           the_flag = 1;
        if(str == 'M')
           the_flag = 2;
        if(str == 'G')
           the_flag = 3;
        if(str == 'T')
           the_flag = 4;
        if(str == 'P')
           the_flag = 5;
        if(str == 'E')
           the_flag = 6;
        if(str == 'Z')
           the_flag = 7;
        if(str == 'Y')
           the_flag = 8;
        if(the_flag == 0)
        {
            printf("0.00");
            printf("%%\n");
        }
        else
        {
            while(the_flag --)
            {
                sum = sum * (1000.0 / 1024.0);
            }
            the_result = (1 - sum) * 100;;
            printf("%.2lf",the_result);
            printf("%%\n");
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/GODLIKEING/p/3432542.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值