一开始不懂事,用 pow(1000.0/1024.0, t)去算,这样会有精度问题,所以还是老老实实用pow(1000.0, t)/pow(1024.0, t)去算
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define INF 1e9
#define maxn
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
int t;
char key[20];
int num, x1, x2, kase;
int check(char* s){
if(s[1]=='B')
return 0;
if(s[1]=='K')
return 1;
if(s[1]=='M')
return 2;
if(s[1]=='G')
return 3;
if(s[1]=='T')
return 4;
if(s[1]=='P')
return 5;
if(s[1]=='E')
return 6;
if(s[1]=='Z')
return 7;
if(s[1]=='Y')
return 8;
}
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
scanf("%d\n", &kase);
rep(ks, 1, kase){
printf("Case #%d: ", ks);
scanf("%d%s", &num, key);
int t = check(key);
double ans = pow(1000.0, t)/pow(1024.0, t);
ans = 1.0 - ans;
printf("%.2lf%%\n", 100.0*ans);
}
return 0;
}