URI ONLINE JUDGE SOLUTION 1304 - Online Judge

Latest

This is an Online Judge Solution Base Site. We can discuss & Solve any contest solution in Programming.

Friday, April 10, 2020

URI ONLINE JUDGE SOLUTION 1304

Problem Number: 1304
Problem Name: Average Speed
Author’s Name: By Gordon Cormack Canada
Timelimit: 2
Problem Category: AD-HOC
Problem Source: https://www.urionlinejudge.com.br/judge/en/problems/view/1304

Solution:

#include <stdio.h>

int main(){
    int h, m, s;
    int tempo = 0;
    int t;
    double distancia = 0;
    int vel;
    char c;
   
    while(scanf("%d:%d:%d", &h, &m, &s) != EOF){
               scanf("%c", &c);
               if(c == ' '){
                    if(tempo != 0) distancia += (double)(((h*3600 + m*60 + s)-tempo)*vel)/3600;
                    scanf("%d%*c", &vel);
                    tempo = h*3600 + m*60 + s;
               }else{
                     distancia += (double)(((h*3600 + m*60 + s)-tempo)*vel)/3600;
                     printf("%02d:%02d:%02d %.2lf kmn", h, m, s, distancia);
                     tempo = h*3600 + m*60 + s;
               }
    }
   
    return 0;
}

No comments:

Post a Comment

Thanks..