HDU 4788 Hard Disk Drive (2013成都H,水题) 进位换算

计算机容量单位转换算法实现
本文介绍了如何使用C++编程语言实现计算机容量单位之间的转换算法,包括从比特到字节的转换过程,并通过实例展示了算法的应用。
 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include<cmath>
 5 using namespace std;
 6 double a;
 7 char s[100];
 8 int fun(char s[]) {
 9     if(strcmp(s,"B]") == 0)return 0;
10     if(strcmp(s,"KB]") == 0)return 1;
11     if(strcmp(s,"MB]") == 0)return 2;
12     if(strcmp(s,"GB]") == 0)return 3;
13     if(strcmp(s,"TB]") == 0)return 4;
14     if(strcmp(s,"PB]") == 0)return 5;
15     if(strcmp(s,"EB]") == 0)return 6;
16     if(strcmp(s,"ZB]") == 0)return 7;
17     if(strcmp(s,"YB]") == 0)return 8;
18 }
19 int main() {
20 //    freopen("in.txt","r",stdin);
21     int t;
22     scanf("%d",&t);
23     int cas=0;
24     while(t--) {
25         scanf("%lf[%s",&a,s);
26         cas++;
27         int num=fun(s);
28         double ans=pow(1000.0,num)/pow(1024.0,num);
29         ans=1-ans;
30         printf("Case #%d: %.2lf%%\n",cas,ans*100);
31     }
32     return 0;
33 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5298885.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值