HDU-#4788 Hard Disk Drive

        题目大意:一块磁盘的大小,人为计算是按照数量级间10^3计算,而计算机是按照2^10计算的。问给定一个数以及单位,求损失了多少容量?

        解题思路:直接计算单位间的损失即可,因为不管多少数据都会约分被约掉,直接求解即可,详见code。

        题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4788

        code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

const int MAXN = 10;
int t,data,cas,cnt;
double ans,tmp;
char str[MAXN];
char *arr[]={"[B]","[KB]","[MB]","[GB]","[TB]","[PB]","[EB]","[ZB]","[YB]"};

int main(){
    scanf("%d",&t);
    while(t--){
        getchar();
        scanf("%d%s",&data,&str);
        for(int i=0;i<MAXN;++i)
            if(strcmp(str,arr[i])==0){
                cnt=i;
                break;
            }
        tmp=1000*1.0/1024;
        ans=pow(tmp,cnt);
        printf("Case #%d: %.2f%%\n",++cas,100*(1-ans));
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值