HDOJ Hard Disk Drive 4788【2013成都区域赛H题-水】

Hard Disk Drive

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

Total Submission(s): 1887    Accepted Submission(s): 1042

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


Source

2013 Asia Chengdu Regional Contest

Recommend

We have carefully selected several similar problems for you:  5326 5325 5324 5323 5322

水~

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

using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	int xp=1;
	while(t--){
		double x=0;
		char s[10];
		scanf("%s",s);
		int l=strlen(s);
		char str[5];
		int i;
		for(i=0;;i++){
			if(s[i]=='[')break;
			x=x*10+(s[i]-'0');
		}
		int k=0;
		for(int j=i+1;j<l-1;j++){
			str[k++]=s[j];
		}
		str[k]='\0';
		double sum=x;
		int xn,dn;
		if(str[0]=='B'){
			sum=x;
		}
		else if(str[0]=='K'){
			sum=sum*1000.0/1024.0;
		}
		else if(str[0]=='M'){
				dn=xn=2;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='G'){
			dn=xn=3;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='T'){
			dn=xn=4;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='P'){
			dn=xn=5;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='E'){
			dn=xn=6;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='Z'){
			dn=xn=7;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		else if(str[0]=='Y'){
			dn=xn=8;
			while(xn--){
				sum*=1000.0;
			}
			while(dn--){
				sum/=1024.0;
			}
		}
		double res=(x-sum)*100.0/x;
		printf("Case #%d: %.2lf%%\n",xp++,res);
	}
    return 0;
}

版权声明:本文为博主原创文章,转载请注明出处。

时间: 2024-10-13 02:22:31

HDOJ Hard Disk Drive 4788【2013成都区域赛H题-水】的相关文章

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

HDOJ Galaxy 5073【2014年鞍山区域赛D题-方差】

Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 2800    Accepted Submission(s): 684 Special Judge Problem Description Good news for us: to release the financial pressure, the governmen

HDOJ Osu! 5078【2014鞍山区域赛I题-水】

Osu! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1263    Accepted Submission(s): 660 Special Judge Problem Description Osu! is a very popular music game. Basically, it is a game about cli

Hihocoder 1634 Puzzle Game(2017 ACM-ICPC 北京区域赛 H题,枚举 + 最大子矩阵变形)

题目链接  2017 Beijing Problem H 题意  给定一个$n * m$的矩阵,现在可以把矩阵中的任意一个数换成$p$,求替换之后最大子矩阵的最小值. 首先想一想暴力的方法,枚举矩阵中的数,然后$O(n^{3})$求最大子矩阵更新答案,这样复杂度是$O(n^{5})$的. 思考得再仔细一些,就是包含这个数的最大子矩阵和,以及不包含这个数的最大子矩阵的和的较大值. 设原矩阵中最大子矩阵和为$mx$. 设$u_{i}$为只考虑矩阵前$i$行的最大子矩阵和,$d_{i}$为考虑矩阵第$

HDU 4791 Alice&#39;s Print Service(2013长沙区域赛现场赛A题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询. 因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * p

36th成都区域赛网络赛 hdoj4039 The Social Network(建图+字符串处理)

这题是某年成都区域赛网络赛的一题. 这题思路非常easy,可是从时间上考虑,不妨不要用矩阵存储,我用的链式前向星. 採用线上查询.利用map对字符串编号,由于非常方便.要推荐的朋友,事实上就是朋友的朋友(这里指的是直接朋友,图中即指有直接边相连的). 所以在寻找时,仅仅须要查找朋友的朋友,并计数. 注意:在输出时不能有对于的空格. 附代码: #include<iostream> using namespace std; #include<cstdio> #include<cs

HDU - 4734 F(x) (2013成都网络赛,数位DP)

题意:求0-B的满足<=F[A]的所有可能 思路:数位DP,记忆化搜索 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; int A, B; int dp[20][200000]; int bit[20]; int dfs(int cur, int num, int flag) { if (cur == -

HDU 4815 2013长春现场赛C题

C - Little Tiger vs. Deep Monkey Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4815 Description A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU. "Are y

[暑假集训]区域赛套题集

2014-07-03 [浙江第11届省赛]ZOJ 3785 What day is that day?  (打表找循环节) [暑假集训]区域赛套题集