竹園論壇

標題: HPCW2014 07 - 酒測安全值 [打印本頁]

作者: HSCHE    時間: 2014-4-21 08:13
標題: HPCW2014 07 - 酒測安全值
本帖最後由 HSCHE 於 2014-4-21 13:51 編輯

題目:
  為了計算是否酒駕請試著做一個程式判斷需多久才能把酒精代謝掉,已知人體最大酒精量必須小於0.05%(500PPM) 人體血量約佔總體重之8% 人體一小時可排出10(ml)的酒精
範例輸入:
2.3 350 5 70
  
第一組數字代表幾手啤酒 前面單位是手(*6) 後面是罐(*1) 第二組數字代表每罐啤酒之容量(為整數) 第三組數字代表酒精濃度為多少% 第四組數字代表人體體重
範例輸出:
 請輸出需多久才能達到酒測安全值(小時:分鐘)

25:59

本人感想:本人覺得這題頗簡單的,基本上只是運算偏多,請注意題目敘述




#include<iostream>
  • #include<cstdio>
  • using namespace std;
  • int main()
  • {
  •         int can,beer,fs,ansh,ansm;
  •         double hand,ach,wei,fsh,weis,ans;
  •         cin>>hand>>beer>>ach>>wei;
  •         //can
  •         can=(int)hand;
  •         fs=(hand-(double)can)*10;
  •         can*=6;
  •         can+=fs;
  •         //cout<<can<<"\n";
  •         //ach
  •         ach=(double)beer*(double)can*ach/100;
  •         //cout<<ach<<"\n";
  •         //weis
  •         weis=wei*8/100*0.05/100*1000;
  •         //cout<<weis<<"\n";
  •         //ans
  •         ans=(ach-weis)/10;
  •         ansh=(int)ans;
  •         fsh=(ans-(double)ansh)*60+0.99;
  •         ansm=(int)fsh;
  •         cout<<ansh<<':'<<ansm;
  •         return 0;
  • }








  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2