1087: 就多了两分钟
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1619 Solved: 431
[ Submit][ Status][ Web Board]
Description
Yucept21和他的室友Zyn因为宿舍没电去网吧上网,上了27分钟,Cs打电话来说来电了。所以Yucept21在第29分钟下机了,上网的费用是一块钱,然后Zyn墨迹了两分钟,第31分钟下机,上机费用是2元。现在知道网吧是按照半个小时计费的,假设半个小时上机的费用是1块钱。现在给你两个时间点,要你求出上机费用和再上多少分钟最划算?(最划算是指上满这个三十分钟,比如上机一个小时四十五分钟,那么再上v = 15分钟最划算)。
Input
输入为一行四个数字,上机时间h1,m1,下机时间h2,m2。 h是小时,m是分钟,采用24小时制。0<=h1,h2<=23
0<=m1,m2<60
Output
输出Day #: 后面两个数字w和v,w为费用,v描述如上,单位分钟。如果上机时间在下机时间的后面则输出"Joking"。
Sample Input
1 48 3 39
20 16 22 6
23 8 1 42
Sample Output
Day 1: 4 9
Day 2: 4 10
Day 3: Joking
HINT
Source
原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1087
刚开始想到模拟,结果就是不对,后来参考了别人的代码,发现直接用结束时间减去开始时间就是上机时间。(PS:我怎么就没有想到呢?)
然后再根据剩余的时间判断是要多交钱呢还是可用用剩下的。
AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int h1,m1,h2,m2;
int kase=0;
//freopen("data/1087.txt","r",stdin);
while(cin>>h1>>m1>>h2>>m2)
{
printf("Day %d: ",++kase);
if(h1>h2||h1==h2&&m1>m2)
{
cout<<"Joking"<<endl;
continue;
}
int t=(h2-h1)*60+m2-m1;
int ans=t/30;
int last=t%30;
if(last)
last=30-t%30;
if(last!=0&&last!=30)
ans++;
cout<<ans<<" "<<last<<endl;
}
return 0;
}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine