[ACM 1280] How many hours have coders slept?

Source: Internet
Author: User
Description

How many hours have he slept in total?

Input has multiple groups of test data, one row in each group, which is the bed time and the bed time. A space is separated between them. Output: for each group of data, the total sleep time of the coders is T (minutes) of course 0 <= T <24*60 sample input01: 00 08: 00 sample output420 540
# Include <algorithm> # include <iostream> # include <string> # include <vector> using namespace STD; int main () {string S1, S2; while (CIN> S1> S2) {int H1 = (S1 [0]-'0') * 10 + (S1 [1]-'0 '); int H2 = (s2 [0]-'0') * 10 + (s2 [1]-'0'); int M1 = (S1 [3]-'0 ') * 10 + (S1 [4]-'0'); int m2 = (s2 [3]-'0 ') * 10 + (s2 [4]-'0'); int flag = 0; // whether to borrow an hour int sum = 0; If (M1> m2) {flag = 1; sum + = (M2 + 60-M1);} else {sum + = (m2-M1);} If (H2> = (H1 + flag )) // equal sign do not forget Oh, critical judgment should be careful {sum + = (h2-h1-flag) * 60);} else {sum + = (H2 + 24-h1-flag) * 60) ;}cout <sum <Endl ;}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.