0
I am getting a compilation error (Compilation error) in the URI site judgment on issue 1046, although it is working perfectly in my Code Blocks. Question:
My code
#include <stdio.h>
#include <stdlib.h>
int main()
{
int hr_inicial, hr_final, duracao;
scanf("%d %d", &hr_inicial, &hr_final);
if((hr_inicial <= 24) && (hr_inicial >= 0) && (hr_final <= 24) && (hr_final >= 0)){
if(hr_inicial == 24){
hr_inicial = 0;
}
if(hr_inicial < hr_final){
duracao = hr_final - hr_inicial;
}
if (hr_inicial > hr_final){
for(int i = 1; i <= 24; i++){
hr_inicial++;
if(hr_inicial == 24){
duracao = i;
i = 1;
}
if(i == hr_final){
duracao += i;
}
}
}
if(hr_inicial == hr_final){
duracao = 24;
}
printf("O JOGO DUROU %d HORA(S)\n", duracao);
}
return 0;
}
What can I have wrong?
But it is not enough to subtract the initial hr_start from the final hr_and if it is negative add 24?
– anonimo
Damn, I should have thought of it, that way it was accepted and did not involve as much logic and code as in my resolution, thanks!
– Leo Lima