首页 > ACM题库 > HDU-杭电 > hdu 2631 Lead A Healthy Life-模拟-[解题报告]C++
2014
02-12

hdu 2631 Lead A Healthy Life-模拟-[解题报告]C++

Lead A Healthy Life

问题描述 :

Samuel concerns about his health condition a lot. He never wants to damage his health by staying up late at night or leaving his stomach empty without having meals. He always goes to bed at 10 pm,and gets up at 7 am next morning. He often goes to the dinning hall at the meal time,even if he is engaged with a lot of work at hand during the dinner time. In a word, healthy regular life holds higher priority than anything else in Samuel’s opinion.
According to the traditional Chinese medical care spirit,breakfast ought to be finished at about 7 am, lunch time at about 12 o’clock, and supper time at about 5 pm. Sleep cannot be later than 1 o’clock am because 1-2 am is a precious time for the liver to relax and rebuild itself. If you have a habit of sleeping later than 2 o’clock, you have to pay more attention to your liver before it is too late. And it has been proved that only by sleeping early and for enough time will your liver function well.
Here are some principles of living a health life:

Samuel holds the view that health is the firm foundation of your work,so he sticks to these principles in order to lead a health life. Will you want to be healthy?
The problem Samuel gives you is to tell whether his friend NeverGone is leading a health life.

输入:

The input includes 2 major parts:
First part is the test number t,an integer.
Second part is the part of each test cases:
Sleep time HH:MM-HH:MM(in 24 hours,time lasts within 24 hours),the bottles one drank a day n,take sports or not(using T/F to describe,always big letter),whether or not stay a good mood(T/F boolean type,the same with the former explanation)

输出:

The input includes 2 major parts:
First part is the test number t,an integer.
Second part is the part of each test cases:
Sleep time HH:MM-HH:MM(in 24 hours,time lasts within 24 hours),the bottles one drank a day n,take sports or not(using T/F to describe,always big letter),whether or not stay a good mood(T/F boolean type,the same with the former explanation)

样例输入:

2
23:59-6:58
8
T
T
24:00-8:00
10
T
T

样例输出:

NeverGone should pay attention to his health!
Health life,NeverGone you should keep doing!
Hint
in the first case although NeverGone does very well in other three aspects,he only sleeps for 6 hours and 59 minutes. According to the principle he at least needs to sleep for 7 hours. So he does not lead a healthy life. In the second case,he does very well on all the aspects so he is leading a healthy life.


简单模拟题!把四个条件搞清楚就好了~


#include<stdio.h>
int main()
{
 int t,h1,m1,h2,m2,n,t1,dh,flag;
 char c;
 scanf(“%d”,&t);
 while(t–&&scanf(“%d:%d-%d:%d”,&h1,&m1,&h2,&m2))
 {
  flag=1;
  if(h1-12<0)flag=0;
  if(h2<h1)h2+=24;
  dh=h2-h1;
  t1=60*dh+m2-m1;
  if(t1<420||t1>480)flag=0;
  scanf(“%d%*c”,&n);
  if(n<8)flag=0;
  scanf(“%c%*c”,&c);
  if(c!=’T')flag=0;
  scanf(“%c%*c”,&c);
  if(c!=’T')flag=0;
  if(flag)printf(“Health life,NeverGone you should keep doing!\n”);
  else printf(“NeverGone should pay attention to his health!\n”);
 }
}

解题转自:http://zc634579757.blog.163.com/blog/static/12449746220098194353777/