URI Online Judge | 1061
Tempo de um Evento
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1
Pedrinho está organizando um evento em sua Universidade. O evento deverá ser no mês de Abril, iniciando e terminando dentro do mês. O problema é que Pedrinho quer calcular o tempo em segundos que o evento vai durar, uma vez que ele sabe quando inicia e quando termina o evento..
Sabendo que o evento pode durar de poucos segundos a vários dias, você deverá ajudar Pedrinho a calcular a duração deste evento.
Entrada
Como entrada, na primeira linha vai haver a descrição “Dia”, seguido de um espaço e o dia do mês no qual o evento vai começar. Na linha seguinte, será informado o momento no qual o evento vai iniciar, no formato hh : mm : ss. Na terceira e quarta linha de entrada haverá outra informação no mesmo formato das duas primeiras linhas, indicando o término do evento.
Saída
Na saída, deve ser apresentada a duração do evento, no seguinte formato:
W dia(s)
X hora(s)
Y minuto(s)
Z segundo(s)
Obs: Considere que o evento do caso de teste para o problema tem duração mínima de 1 minuto.
W dia(s)
X hora(s)
Y minuto(s)
Z segundo(s)
Obs: Considere que o evento do caso de teste para o problema tem duração mínima de 1 minuto.
URI Online Judge | 1061
Event Time
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Peter is organizing an event in his University. The event will be in April month, beginning and finishing within April month. The problem is: Peter wants to calculate the event duration in seconds, knowing obviously the begin and the end time of the event.
You know that the event can take from few seconds to some days, so, you must help Peter to compute the total time corresponding to duration of the event.
Input
The first line of the input contains information about the beginning day of the event in the format: “Dia xx”. The next line contains the start time of the event in the format presented in the sample input. Follow 2 input lines with same format, corresponding to the end of the event.
Output
Your program must print the following output, one information by line, considering that if any information is null for example, the number 0 must be printed in place of W, X, Y or Z:
W dia(s)
X hora(s)
Y minuto(s)
Z segundo(s)
Obs: Consider that the event of the test case have the minimum duration of one minute. “dia” means day, “hora” means hour, “minuto” means minute and “Segundo” means second in Portuguese.
W dia(s)
X hora(s)
Y minuto(s)
Z segundo(s)
Obs: Consider that the event of the test case have the minimum duration of one minute. “dia” means day, “hora” means hour, “minuto” means minute and “Segundo” means second in Portuguese.
#include<stdio.h>
int main(){
int dia, diafim, hora, horafim, minuto, minutofinal, segundo, segundofinal;
scanf("Dia %d", &dia);
scanf("%d : %d : %d\n", &hora, &minuto, &segundo);
scanf("Dia %d", &diafim);
scanf("%d : %d : %d", &horafim, &minutofinal, &segundofinal);
segundo = segundofinal - segundo;
minuto = minutofinal - minuto;
hora = horafim - hora;
dia = diafim - dia;
if (segundo < 0){
segundo += 60;
minuto--;
}
if (minuto < 0){
minuto += 60;
hora--;
}
if (hora < 0){
hora += 24;
dia--;
}
printf("%d dia(s)\n", dia);
printf("%d hora(s)\n", hora);
printf("%d minuto(s)\n", minuto);
printf("%d segundo(s)\n", segundo);
}
Nenhum comentário:
Postar um comentário