题目大意:一块磁盘的大小,人为计算是按照数量级间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;
}