【Hard Disk Drive 】(简单题 2013icpc成都)

题目:

Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will get married next year. 
  But you turned on your computer and the operating system (OS) told you the HDD is about 95MB. The 5MB of space is missing. It is known that the HDD manufacturers have a different capacity measurement. The manufacturers think 1 “kilo” is 1000 but the OS thinks that is 1024. There are several descriptions of the size of an HDD. They are byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zetabyte and yottabyte. Each one equals a “kilo” of the previous one. For example 1 gigabyte is 1 “kilo” megabytes. 
  Now you know the size of a hard disk represented by manufacturers and you want to calculate the percentage of the “missing part”.

Input

  The first line contains an integer T, which indicates the number of test cases. 
  For each test case, there is one line contains a string in format “number[unit]” where number is a positive integer within [1, 1000] and unit is the description of size which could be “B”, “KB”, “MB”, “GB”, “TB”, “PB”, “EB”, “ZB”, “YB” in short respectively.

Output

  For each test case, output one line “Case #x: y”, where x is the case number (starting from 1) and y is the percentage of the “missing part”. The answer should be rounded to two digits after the decimal point.

Sample Input

2
100[MB]
1[B]

Sample Output

Case #1: 4.63%
Case #2: 0.00%


        
  

Hint

         
  

解题报告:这道题目看到的时候,第一眼觉得有点难,但是后来发现就是一个字符串的判断,在数据前边的数字其实没有什么用处,他的内存丢失的原因是1MB=10^3KB 和 1MB=2^10KB的区别,只要去判断他所在的容量阶级就可以去找到矛盾了,然后用快速幂去求解就行,提交之前还在担心会不会爆数据范围,后来发现是有一定的可能的,所以我后来直接在本地进行求解,把这几个数据的容量的数据遗失比去计算出来,在程序中直接去判断阶级,然后输出数字就可以,避免了爆数据范围。

ac代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;

int T;
int find(char c)
{
	if(c=='B')
		return 1;
	else if(c=='K')
		return 3;
	else if(c=='M')
		return 6;
	else if(c=='G')
		return 9;
	else if(c=='T')
		return 12;
	else if(c=='P')
		return 15;
	else if(c=='E')
		return 18;
	else if(c=='Z')	
		return 21;
	else if(c=='Y')
		return 24;
} 
int ksm(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=res*a;
		a=a*a;
		b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d",&T);
	char str[20];
	int cnt=0;
	while(T--)
	{
		scanf("%s",&str);	
		int num=0;
		int rank;
		for(int i=0;i<strlen(str);i++)
		{
			if(str[i]>'0'&&str[i]<'9')
				num=num*10+(str[i]-'0');
			if(str[i-1]=='[')
			{
				rank=find(str[i]);
			}
		}
		printf("Case #%d: ",++cnt);
	//	printf("%.2lf%%\n",slove(rank));
		if(rank==1)
			printf("0.00%%\n");
		else if(rank==3)
			printf("2.34%%\n");
		else if(rank==6)
			printf("4.63%%\n");
		else if(rank==9)
			printf("6.87%%\n");
		else if(rank==12)
			printf("9.05%%\n");
		else if(rank==15)
			printf("11.18%%\n");
		else if(rank==18)
			printf("13.26%%\n");
		else if(rank==21)
			printf("15.30%%\n");
		else if(rank==24)
			printf("17.28%%\n");
	}		
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值