Header Ads

Header ADS

Solution of URI 1061::Event Time

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>
int main() {
    int day1,day2,hour1,hour2,min1,min2,sec1,sec2,fday,fhour,fmin,fsec;
    char Dia[4],Colon[2];

    scanf("%s%d",Dia,&day1);
    scanf("%d%s%d%s%d",&hour1,Colon,&min1,Colon,&sec1);
    scanf("%s%d",Dia,&day2);
    scanf("%d%s%d%s%d",&hour2,Colon,&min2,Colon,&sec2);


    if(sec2<sec1) {
        sec2=sec2+60;
        fsec=sec2-sec1;
        min1=min1+1;
    }
    if(min2<min1) {
        min2=min2+60;
        fmin=min2-min1;
        hour1=hour1+1;

    }
    if(hour2<hour1) {
        hour2=hour2+24;
        fhour=hour2-hour1;
        day1=day1+1;
    }

    fsec=sec2-sec1;
    fmin=min2-min1;
    fhour=hour2-hour1;
    fday=day2-day1;

    printf("%d dia(s)\n%d hora(s)\n%d minuto(s)\n%d segundo(s)\n",fday,fhour,fmin,fsec);

    return 0;
}

No comments

Theme images by konradlew. Powered by Blogger.