Header Ads

Header ADS

Solution of URI 1047::Game Time with Minutes

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 sh,sm,eh,em,dh,dm;

    scanf("%d%d%d%d",&sh,&sm,&eh,&em);

    dh=eh-sh;
    dm=em-sm;

    if(dh==0 && dm==0 ) {
        dh=dh+24;
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
        return 0;
    }

    else if (dh>0 && dm<0) {
            dh=dh-1;
            dm=60+dm;
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
        return 0;
    }

    else if (dh<0 && dm>0) {
            dh=(23-sh) + (1+eh);
          if(dh>24) {
            dh=dh-24;
            printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
          }
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
        return 0;
    }

    else if (dh<0 && dm<0) {
            dh=(23-sh) + (1+eh);
            if (dh>24) {
                dh=dh-24;
                dh=dh-1;
                dm=60+dm;
                printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
                return 0;
            }
            dh=dh-1;
            dm=60+dm;
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);
        return 0;
    }

    printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",dh,dm);

    return 0;
}

No comments

Theme images by konradlew. Powered by Blogger.