hdu 4788 Hard Disk Drive

一道简单题,题意是我们平常生活中见到的例子,平常的u盘,说是8G,但在电脑上显示的是7G多一点儿,是什么原因呢?这道题目给出了解释,为了方便计算,生产商的容量是按照1000算的,而在计算机中容量是按1024算的,所以就出现了偏差,这道题目让计算指定的容量,相对来说丢失了多少容量。
直接计算就可以了,可以使用pow函数来快速计算。最后要输出百分数,所以要乘以100。
代码如下:
/*************************************************************************
	> File Name: c.cpp
	> Author: gwq
	> Mail: gwq5210@qq.com 
	> Created Time: 2014年10月29日 星期三 22时23分42秒
 ************************************************************************/

#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>

#define INF (INT_MAX / 10)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define pb push_back
#define sz(a) ((int)(a).size())

using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;

const double esp = 1e-5;

char type[][10] = {"[B]", "[KB]", "[MB]", "[GB]", "[TB]", "[PB]", "[EB]", "[ZB]", "[YB]"};

int main(int argc, char *argv[])
{
	int t;
	scanf("%d", &t);
	for (int cs = 1; cs <= t; ++cs) {
		int num;
		int pos = 0;
		char str[10];
		double ans = 0.0;
		scanf("%d%s", &num, str);
		for (int i = 0; i < 9; ++i) {
			if (strcmp(str, type[i]) == 0) {
				pos = i;
				break;
			}
		}
		if (pos == 0) {
			ans = 0.0;
		} else {
			ans = 100.0 * (1.0 - pow(1000.0, pos) / pow(1024.0, pos));
		}
		printf("Case #%d: %.2f%%\n", cs, ans);
	}

	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值