Poj 2501 average speed (a good question)

Source: Internet
Author: User

[Title Description]: Give us time and speed, and let us find the distance from leaving

[Analysis]: The question was not clearly displayed at the beginning, so I understood it after looking at other people's questions.

Summary of this question:

1. Time Input Method: scanf ("% d: % d", & H, & M, & S). Pay attention to accumulation!

2. for space input control, char CH = getchar () is used. It also serves as a condition for determining whether to output an identifier.

3. accumulate more methods for similar questions.


Code reference.

// 144K 0Ms#include<iostream>using namespace std;int cal(int h,int m,int s){      return h*3600+m*60+s;  }int main(){int h,m,s;      double speed=0;      double ans=0;      int last=0;     while(scanf("%d:%d:%d",&h,&m,&s)!=EOF)    {    char ch = getchar();    if(ch == ' ')    {    int a;    scanf("%d",&a);    int now = cal(h,m,s);    ans += (now - last)*speed;    last = now;    speed = a/3.6;    }    else    printf("%02d:%02d:%02d %.2f km\n",h,m,s,((cal(h,m,s)-last)*speed+ans)/1000);    }    return 0;}


Poj 2501 average speed (a good question)

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.