Title Link: HDU 4788 hard Disk Drive
Surface:
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 gave you a new 100MB hard disk drive (HDD) as a gift because yo U'll get married next year.
But your turned on your computer and the operating system (OS) told you the HDD are about 95MB. The 5MB of space is missing. It's known that the HDD manufacturers has a different capacity measurement. The manufacturers think 1 "kilo" is and the OS thinks that's 1024. There is several descriptions of the size of an HDD. They is 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 your 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, +] and unit is the description of size which could are "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 Percen Tage of the "missing part". The answer should is rounded to both digits after the decimal point.
Sample Input
2100[MB]1[B]
Sample Output
Case #1:4.63%case #2:0.00%Hint
Source2013 Asia Chengdu Regional Contest
Solving:
Disks and systems are different for file size definitions, and the loss rate is the number of disks that are asked for n x units.
In fact, regardless of the size of the file, only with the unit, each into a unit multiplied by 1000/1024.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <map># Include <cmath> #include <cstdlib> #include <set> #include <algorithm> #include <string># Include <iomanip> #define LL long longusing namespace std;double loss=1000.0/1024;double ans[10]={1.0};void cal () { for (int i=1;i<10;i++) { ans[i]=ans[i-1]*loss;}} void Show (int p) {cout<<fixed<<setprecision (2) << (1-ans[p]) *100<< "%\n";} int main () {int n,t;cal (); cin>>t;string s;for (int i=1;i<=t;i++) {cout<< "Case #" <<i<< ":"; Cin>>n>>s;if (s[1]== ' B ') show (0), else if (s[1]== ' K ') show (1), Else if (s[1]== ' M ') show (2), else if (s[1]== ' G ') Show (3), else if (s[1]== ' T ') show (4), else if (s[1]== ' P ') show (5), else if (s[1]== ' E ') show (6), else if (s[1]== ' Z ') show (7); else if (s[1]== ' Y ') show (8);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4788 Hard Disk Drive