Saturday, 6 February 2016

Solution of URI 1061 :: Event Time


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    char a[4], b[2],c[2],d[2],e[2],f[4];
    int i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z,h[5];
    scanf("%s%d", a,&i);
    scanf("%d%s%d%s%d", &j,&b,&k,&c,&l);
    scanf("%s%d", &f,&p);
    scanf("%d%s%d%s%d", &q, &d,&r,&e,&s);
    m=60-l+s;
    n=(60-k-1+r)*60;
    t=(24-1-j+q)*3600;
    u=(p-i-1)*86400;
    v=m+n+t+u;

    h[0]=v/86400;
    printf("%d dia(s)\n", h[0]);

    h[0]=v%86400;
    h[1]=h[0]/3600;
    printf("%d hora(s)\n", h[1]);

    h[1]=h[0]%3600;
    h[2]=h[1]/60;
    printf("%d minuto(s)\n", h[2]);

    h[2]=h[1]%60;
    printf("%d segundo(s)\n", h[2]);
    return 0;
}

9 comments:

  1. thanks year..i got diff idea from your code. thanks again.

    ReplyDelete
  2. scanf("%s%d", a,&i); ekhane ki &a hobe nah bro??

    ReplyDelete
  3. #include

    int main()
    {
    int A,B,C,D,E,F,G,H,day,hour,minute,second;

    printf("Dia ");
    scanf("%d",&A);
    scanf("%d : %d : %d",&B,&C,&D);

    printf("Dia ");
    scanf("%d",&E);
    scanf("%d : %d : %d",&F,&G,&H);

    if(D>H)
    {
    second=60+H-D;
    G=G-1;
    }
    else
    {
    second=H-D;
    }

    if(C>G)
    {
    minute=60+G-C;
    F=F-1;
    }
    else
    {
    minute=G-C;
    }

    if(B>F)
    {
    hour=24+F-B;
    E=E-1;
    }
    else
    {
    hour=F-B;
    }

    day=E-A;

    printf("%d dia(s)\n%d hora(s)\n%d minuto(s)\n%d segunda(s)\n",day,hour,minute,second);


    return 0;
    }

    what is problem with this code ???

    uri tell 100% error

    Thanks

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      char day1[4],day2[4],colon1[2],colon2[2],colon3[2],colon4[2];
      int day3,day4,h1,m1,s1,h2,m2,s2,day,hour,minute,second;
      scanf("%s %d",day1,&day3);
      scanf("%d %s %d %s %d",&h1,colon1,&m1,colon2,&s1);

      scanf("%s %d",day2,&day4);
      scanf("%d %s %d %s %d",&h2,colon3,&m2,colon4,&s2);
      if(s1>s2)
      {
      second=60+s2-s1;
      m2=m2-1;
      }
      else
      {
      second=s2-s1;
      }
      if(m1>m2)
      {
      minute=60+m2-m1;
      h2=h2-1;
      }
      else
      {
      minute=m2-m1;
      }
      if(h1>h2)
      {
      hour=24+h2-h1;
      day4=day4-1;
      }
      else
      {
      hour=h2-h1;
      }
      day=day4-day3;
      printf("%d dia(s)\n",day);
      printf("%d hora(s)\n",hour);
      printf("%d minuto(s)\n",minute);
      printf("%d segundo(s)\n",second);
      return 0;
      }


      See my code i copy from yours with little bit changes

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. #include

    int main()
    {
    int d=0, h=0, m=0, s=0, ds, hs, ms, ss, de, he, me, se;

    char a[4], b[2];

    scanf("%s%d", &a, &ds);
    scanf("%d%s%d%s%d", &hs, &b, &ms, &b, &ss);

    scanf("%s %d", &a, &de);
    scanf("%d%s%d%s%d", &he, &b, &me, &b, &se);

    d = de-ds;
    h = he-hs;
    if(h<0)
    {
    h+=24;
    d-=1;
    }
    m = me-ms;
    if(m<0)
    {
    m+=60;
    h-=1;
    }
    s = se-ss;
    if(s<0)
    {
    s+=60;
    m-=1;
    }

    printf("%d dia(s)\n%d hora(s)\n%d minuto(s)\n%d segundo(s)\n", d, h, m, s);

    return 0;
    }



    comparing this code and your code, which is better and why ? Would you please explain ?

    ReplyDelete
    Replies
    1. your's so much cleaner and makes more sense

      Delete

Note: only a member of this blog may post a comment.