立志用更少的代码做更高效的表达


 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%


1、在printf中, %的输出格式是:%%

2、比例是固定的,与数字没关系,因此采用映射或打表。


代码展示

#include<iostream>
#include<map>
#include<string>
using namespace std;
int main() {map<string, int>m;  m["[B]"]=0;  m["[KB]"]=1; m["[MB]"]=2; m["[GB]"]=3;m["[TB]"]=4; m["[PB]"]=5; m["[EB]"]=6; m["[ZB]"]=7; m["[YB]"]=8;  int T = 0;int n; cin >> n;  while(n--) { int d; string s; cin >> d >> s;printf("Case #%d: ", ++T);if(s == "[B]") cout << "0.00%" << '\n';else {double d = 1;for(int i = 0; i < m[s]; i++) {d *= 1000.0;d /= 1024;}printf("%.2lf%%\n", (1-d)*100);} }
return 0; }

每日一句

忍耐不是美德,把忍耐当成美德是这个伪善的世界维持它扭曲的秩序的方式。 生气才是美德。

                             ——《房思琪的初恋乐园》

Hard Disk Drive HDU - 4788——24行代码AC,解题报告相关推荐

  1. Hard Disk Drive HDU - 4788

    Hard Disk Drive HDU - 4788 题意: 通常制造商认为1"kilo"等于1000,但操作系统会认为是1024. 因此,当你购买了一个100MB的硬盘,电脑却只 ...

  2. [Python私活案例]24行代码,轻松赚取400元,运用Selenium爬取39万条数据

    今天分享一单来自金主爸爸的私单,运用简单的爬虫技巧,可以有效的规避反爬机制,正所谓"你有张良计,我有过云梯".这个案例也很好的体现了python语音的优势,规避了非常复杂的底层逻辑 ...

  3. 基于华为云会议SDK 24行代码打造企业专属会议室

    华为已经有着超过20年的视频会议产品研发经验,拥有1000多项视频会议.音视频相关的国际和国内专利技术.华为云会议基于全开放的产品定位,将华为云会议的所有产品能力都开放给伙伴,伙伴可以通过集成华为云会 ...

  4. 12行代码AC——L1-058 6翻了(15分)

    立志用更少的代码做更高效的表达 "666"是一种网络用语,大概是表示某人很厉害.我们很佩服的意思.最近又衍生出另一个数字"9",意思是"6翻了&quo ...

  5. 【简洁代码】1028 List Sorting (25 分)_26行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Excel can sort records according to any column. Now you are suppo ...

  6. 15行代码AC——1019 数字黑洞 (20分) 甲级1069. The Black Hole of Numbers (20)(解题报告)

    立志用更少的代码做更高效的表达 PAT甲级最优题解-->传送门 Pat乙级最优化代码+题解+分析汇总-->传送门 给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非 ...

  7. 7行代码AC——1010 一元多项式求导 (25分)

    立志用更少的代码做更高效的表达 Pat乙级最优化代码+题解+分析汇总-->传送门 设计函数求一元多项式的导数.(注:x​n(n为整数)的一阶导数为n*x​n-1​​ .) 输入格式: 以指数递降 ...

  8. 15行代码AC——ZOJ - 4118 Stones in the Bucket(思维题+优化方案)(第十届山东省ACM程序设计竞赛F题)

    励志用少的代码做高效表达. 思路分析 题意:给定n个数,问最少操作几次,使数列中的数全部相等. 操作一:将数列中任意数减一. 操作二:将数列中任意数减一.任意数加一(相当于把1挪过去) 涉及到最少的题 ...

  9. 16行代码AC——例题6-4破损的键盘(Broken Keyboard,UVa 11988)——解题报告

    励志用尽量少的代码做高效的表达. 题目(提交)链接→UVa-11988 题目大意: 输入一个字符串,输出在原本应该是怎么样的? 具体方法是: 若读取到'[', 则执行Home键:将光标移到行首. 若读 ...

最新文章

  1. 编译器设计-有限自动机
  2. mysql超大数据库备份
  3. 查看tensorflow pb模型文件的节点信息
  4. vue-自定义过滤器--时间
  5. Linux:网络编程
  6. 【C++】45.尽量不要在构造函数中调用函数或开启线程
  7. 搞懂这四个问题,企业数字化转型才可能成功
  8. 2017 软件开发薪酬调查:Go 和 Scala 是最赚钱的语言
  9. 二叉树题目---3 另一个树的子树 AND 二叉树最大深度
  10. MATLAB求图片两圆圆心,求助:如何求此图中两圆的圆心距?
  11. 什么是python全栈开发_什么是python全栈
  12. 【SQL练习题】排序
  13. 用进化的观点学习网络协议
  14. CocosCreator如何制作微信小游戏
  15. HCIE-Routing Switching认证
  16. 特效制作思路(技术层面)
  17. 图像分割之(四)OpenCV的GrabCut函数使用和源码解读
  18. 360城市全景,开启全新城市探索方式
  19. 说说JavaScript的原型链
  20. 技术选型系列 -- Redis VS Memcached

热门文章

  1. Socket之UDP客户端【Python】
  2. 《MySQL实战45讲》实践篇 9-15讲 学习笔记
  3. 面试题:1 到 1000 之间有多少个 7?
  4. 揭秘视频千倍压缩背后的技术原理之预测技术
  5. 【大会】AI向多媒体各细分场景渗透
  6. LiveVideoStackCon讲师热身分享 ( 七 ) —— 视频编码器的对比与选择
  7. 腾讯云首次公开边缘计算网络开源平台,拥抱5G与万物互联
  8. Oceanus:基于Apache Flink的一站式实时计算平台
  9. ../configure: /bin/sh^M: bad interpreter: No such file or directory
  10. 游戏服务器正式发布时动态库处理的两种策略