URI Problem 1061

1

Hello everyone, I am using a website to try to make a programming request. link

I'm in Exercise 1061: link

WhenIsendmycode,itsaysthatithas30%error,couldanyonehelpme?

code:

#include<stdio.h>intmain(){intW,X,Y,Z,d1,h1,m1,s1,d2,h2,m2,s2,st1,st2,stf;chardia1[3],dia2[3],krct;//krcteusadoparalero://dia1edia2eusadoparalerapalavraDia/*h1=hora1m1=minuto1s1=segundo1h1=hora2m1=minuto2s1=segundo2st1=somadesegundosdotempo1st2=somatotaldesegundosdotempo2stf=somatotaldesegundos*///leituradeDIAd1h1:m1:s1scanf("%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 used:

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

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

After turning the two times in seconds and only subtracting time 2 with 1 and turning that result into day: hour: minutes: seconds in only 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
    
asked by anonymous 13.03.2016 / 23:23

1 answer

2

Problem solved

problem was in the scanf the pergunda asks it to be so

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