URI Problem 1061

Asked

Viewed 5,005 times

1

Hello guys I’m using a site to try to do some programming dessafios o https://www.urionlinejudge.com.br

I’m in exercise 1061:https://www.urionlinejudge.com.br/repository/UOJ_1061.html

inserir a descrição da imagem aqui

When I send my code he says he’s in 30% error someone could help me?

code:

 #include <stdio.h>

int main()
{
    int W,X,Y,Z,d1,h1,m1,s1,d2,h2,m2,s2,st1,st2,stf;
    char dia1[3],dia2[3],krct;
    //krct e usado para ler o :
    //dia1 e dia2 e usado para ler a palavra Dia
    /*
        h1=hora 1
        m1=minuto 1
        s1=segundo1
        h1=hora 2
        m1=minuto 2
        s1=segundo 2
        st1=soma de segundos do tempo 1
        st2=soma total de segundos do tempo 2
        stf=soma total de segundos
    */

    //leitura de DIA d1 h1 : m1 : s1

    scanf("%s %d %d %s %d %s %d",&dia1,&d1,&h1,&krct,&m1,&krct,&s1);
      //leitura de Dia d2 h2 : m2 : s2
    scanf("%s %d %d %s %d %s %d",&dia2,&d2,&h2,&krct,&m2,&krct,&s2);

    st1=(s1+m1*60+h1*60*60+d1*60*60*24);//calculo para transformar em segundos
    st2=(s2+m2*60+h2*60*60+d2*60*60*24);//caluclo para transformar em segundos


    stf=(st2-st1);
    W=stf/(60*60*24);//calculo para dia
    X=(stf-W*60*60*24)/(60*60);//calculo para hora
    Y=(stf-W*60*60*24-X*60*60)/60;//calculo para minuto
    Z=stf-W*60*60*24-X*60*60-Y*60;//calculo para segundos

    //exibe na tela a resposta:
    printf("%d dia(s)\n",W);
    printf("%d hora(s)\n",X);
    printf("%d minuto(s)\n",Y);
    printf("%d segundo(s)\n",Z);

}

logite usada:

transform the time that is in day:hour:minutes:seconds in just seconds using the equation

total seconds=seconds+minute*60+hour*60*60+day*60*60*24

after transforming the two times into seconds and only subtract the time 2 with the 1 and turn that result into day:hour:minutes:seconds in just seconds using these equations;

W=stf/(60*60*24);//calculo para dia
X=(stf-W*60*60*24)/(60*60);//calculo para hora
Y=(stf-W*60*60*24-X*60*60)/60;//calculo para minuto
Z=stf-W*60*60*24-X*60*60-Y*60;//calculo para segundos

1 answer

2

Problem solved

problem was in the scanf the question asks it so

 scanf("Dia %d",&d1);
    scanf("%d : %d : %d\n",&h1,&m1,&s1);
    scanf("Dia %d",&d2);
    scanf("%d : %d : %d",&h2,&m2,&s2);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.