Problem in question 1046 of the URI site

0

I'm getting a compilation error in the URI site judgment in question 1046, although it's working perfectly on my Code Blocks. Question:  

Mycode

#include<stdio.h>#include<stdlib.h>intmain(){inthr_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 do wrong?

    
asked by anonymous 29.11.2018 / 22:54

1 answer

0

Here's the resolution:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int hr_inicial, hr_final, duracao;
    scanf("%d %d", &hr_inicial, &hr_final);

        if(hr_inicial < hr_final){
            duracao = hr_final - hr_inicial;
        }
        if(hr_inicial > hr_final){
            duracao = (hr_final - hr_inicial) +24;
        }
        if(hr_inicial == hr_final){
            duracao = 24;
        }
        printf("O JOGO DUROU %d HORA(S)\n", duracao);

    return 0;
}
    
30.11.2018 / 00:32