HDU 4788——Hard Disk Drive

求硬盘厂家标注的容量跟实际容量的差距。代码如下:

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

double B[]={1,1000,1e6,1e9,1e12,1e15,1e18,1e21,1e24};

double po(int pos){
    double p=1;
    for(int i=0;i<pos;++i){
        p=p*pos;
    }
    return p;
}

int main(){
 //   freopen("data.txt","r",stdin);
    int T;
    scanf("%d",&T);
    int kase=0;
    while(T--){
        char s[15];
        scanf("%s",s);
        int pos=0;
        int num=0;
        for(int i=strlen(s);i>=0;--i){
            if(s[i]>='0'||s[i]<='9'){
                num=num+(s[i]-'0')*po(pos);
                pos++;
            }
        }
        char tmp=s[strlen(s)-3];
        int rec;
        if(tmp=='['){
            rec=0;
        }
        else if(tmp=='K')rec=1;
        else if(tmp=='M')rec=2;
        else if(tmp=='G')rec=3;
        else if(tmp=='T')rec=4;
        else if(tmp=='P')rec=5;
        else if(tmp=='E')rec=6;
        else if(tmp=='Z')rec=7;
        else if(tmp=='Y')rec=8;
        int times=10*rec;
        double p=1;
        for(int i=0;i<times;++i){p*=2;}
        double ans=1-(B[rec]/p);
        ans*=100;
  //      cout<<"tmp="<<tmp<<endl;
        printf("Case #%d: %.2lf%%\n",++kase,ans);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值