编程介的小学生 2019-11-30 23:31 采纳率: 0.4%
浏览 97

Lead A Healthy Life 代码怎么做的

Problem Description
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.

Input
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)

Output
Only if his living matches the four pieces of the principle above can you say he is leading a health life,so please output”Health life,NeverGone you should keep doing!”otherwise output”NeverGone should pay attention to his health!”.

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

Sample Output
NeverGone should pay attention to his health!
Health life,NeverGone you should keep doing!

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-29 06:04
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # Sample data
    sleep_times <- c(23:59 - 6:58)
    nights <- c(8)
    
    # Convert sleep times to datetime format
    sleep_times_datetime <- as.POSIXct(sleep_times, format="%H:%M-%H:%M")
    
    # Check if all nights are between 7am and 5pm (inclusive)
    valid_nights <- all(night >= 7 & night <= 5 for (night in nights))
    
    # Calculate the total minutes spent sleeping per night
    total_minutes_sleeping_per_night <- cumsum(difftime(sleep_times_datetime, "1970-01-01", units = "mins"))
    
    # Check if there is any night where the total minutes spent sleeping is less than 8 hours
    bad_night <- any(total_minutes_sleeping_per_night < 8 * 60)
    
    # Output the result based on the valid_nights and bad_night conditions
    output <- paste("NeverGone should pay attention to his health!", ifelse(valid_nights, "you should keep doing!", "should do"))
    cat(output)
    
    评论

报告相同问题?