HDU 4788 (14.05.12)

Hard Disk Drive

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 647    Accepted Submission(s): 350

Problem Description

  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


题意: 就是商家生产硬盘时 计算大小时 换算数值是1000 而我们计算机是按1024算的 所以 商家生产的100MB大小硬盘 在电脑上就只剩95MB了 要我们计算丢失百分比.

做法: 其实我做到后面发现其实很简单的 就拿100MB来说 100*1000 /1024*1000/1024 = 95 .3674 这是计算机认为的量 然后 (1-95.3674/100)*100= 4.63 就是比率了, 如果其实把100换成其他数字 这个比率是不变的! 例如换成10 那么 10*1000/1024*1000/1024 = 9.53674 然后(1- 9.53674/10)*100 = 4.63 然后 既然这样的话 我就都用100来算...

AC代码:

#include<stdio.h>
#include<string.h>

int main() {
	double num;
	char str[50];
	int n, cas = 0;
	int count, len;
	scanf("%d", &n);
	getchar();
	while(n--) {
		gets(str);
		num = 100;
		count = 0;
		len = strlen(str);
		for(int i = 0; i < len; i++) {
			if(str[i] == ‘B‘) {
				if(str[i-1] == ‘K‘)
					count = 1;
				else if(str[i-1] == ‘M‘)
					count = 2;
				else if(str[i-1] == ‘G‘)
					count = 3;
				else if(str[i-1] == ‘T‘)
					count = 4;
				else if(str[i-1] == ‘P‘)
					count = 5;
				else if(str[i-1] == ‘E‘)
					count = 6;
				else if(str[i-1] == ‘Z‘)
					count = 7;
				else if(str[i-1] == ‘Y‘)
					count = 8;
			}
		}

		if(count == 0)
			printf("Case #%d: 0.00%%\n", ++cas);
		else {
			while(count--) {
				num *= 1000;
				num /= 1024;
			}
			num = 100 - num;
			printf("Case #%d: %.2lf%%\n", ++cas, num);
		}
	}
	return 0;
}

HDU 4788 (14.05.12),布布扣,bubuko.com

时间: 2024-10-18 14:56:51

HDU 4788 (14.05.12)的相关文章

[14.05.12]今后讨论班的走向

今后讨论班的一些走向 谨记之...... 上周末决定,今后讨论班将针对CVPR 2014和SIAM Conference on IMAGING SCIENCE(2014) 进行进一步的挖掘.上级给我们刚刚布置了SIAM会议的日程.内容安排,看完之后,顿觉亚历山大啊......会是好会,会址更是博主心仪之地.虽不能至,心向往之...... http://www.math.hkbu.edu.hk/SIAM-IS14/ 会议介绍里面有个词用的很好:from nano-scale to the astr

HDU - 4788 Hard Disk Drive (成都邀请赛H 水题)

HDU - 4788 Hard Disk Drive Time Limit:1000MS   Memory Limit:32768KB   64bit IO Format:%I64d & %I64u [Submit]  [Go Back]  [Status] Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will

HDU 4788 Hard Disk Drive

题目链接:HDU 4788 Hard Disk Drive 题面: Hard Disk Drive Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1872    Accepted Submission(s): 1028 Problem Description Yesterday your dear cousin Coach Pang

[hdu 4899]14年多校第四场C Hero meet devil 状压DP

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 122    Accepted Submission(s): 49 Problem Description There is an old country and the king fell in love with a devil. The devil always asks th

uniGUI动态建立Form及释放 (2015-10-01 14:51:12)

uniGUI动态建立Form及释放 (2015-10-01 14:51:12) 转载▼   分类: uniGUI 用uniGUI开发的项目中,难免要遇到动态建立一个Form,再释放掉,与传统Delphi项目不一样,这是从forum转贴过来的,要这样写: //建立方法if Frm = nil then  Frm := TUniForm1.Create(UniApplication); //调用及释放方法Frm.ShowModal(       Procedure(Sender: TComponen

怎样安装 OpenJDK 8 in Ubuntu 14.04 &amp; 12.04 LTS

OpenJDK Java 8 has been made into official Ubuntu repositories for 14.10 Utopic and higher. For Ubuntu 14.04, Ubuntu 12.04, and Linux Mint 17 users here’s how to install it from PPA(Personal Pakage Archives)个人软件包档案.它是Ubuntu Launchpad网站提供的一项服务,允许个人用户上

2016.05.12初识HTML5-01

啊呀~今天本来应该是和朋友出去游玩的,可是却变成了生产实习...今年的生产实习和以往有所不同,以往的都是老师带着学生到工厂里转一转糊弄糊弄就过去了.但这一次要改革了,由我们这的一家软件外包公司负责,来这里进行5天的HTML5授课(说白了就是来宣传的).4天授课,最后一天进行网页制作并且演讲答辩,感觉有点紧啊~不过既然是学习的机会,挺不错的,我会尽力的. 今天主要诠释了什么是HTML5,Hyper Text Markup Language,对,它是一种标签语言.各种各样的标签进行嵌套.相互作用,构

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

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]"

安徽科技学院2014-2015-1学期计算机14级12班《C语言程序设计I》期末考试

1274 Problem A 十字架 Time Limit:1000MS  Memory Limit:65536K Total Submit:5 Accepted:4 Description 现在给你一个7*7的正方形,让你来数一数这个正方形中有多少的十字架.一个十字形为一个十字架,多个个十字架可以相连. 例如:1 1 0 1 0 1 0 1 1 1 1 1 1 1 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1