Saturday 5 May 2012

UVa 10055 Hashmat the brave warrior Solution

#include<stdio.h>
int main()
{
long long int a,b,c;
while(scanf("%lld%lld",&a,&b)==2)
{
if(a>b)
c=a-b;
else
c=b-a;
printf("%lld\n",c);
}
return 0;
}

16 comments:

  1. (scanf("%lld%lld",&a,&b)==2 what does the condition mean?

    ReplyDelete
    Replies
    1. it means, process the input till End Of File. while there is two more long long data in the input file,process it. otherwise, terminate the program.
      you can do it the following way too...
      while(scanf("%lld %lld", &a, &b)!=EOF)

      Delete
    2. what difference does this statement makes?

      Delete
  2. #include
    int main()
    {
    int x,y;
    while (scanf("%d %d", &x, &y)==2)
    {
    if (x>y)
    printf("%d/n", x-y);
    else
    printf("%d/n", y-x);
    }

    return 0;
    }

    ReplyDelete
  3. #include
    int main()
    {
    int x,y;
    while (scanf("%d %d", &x, &y)==2)
    {
    if (x>y)
    printf("%d/n", x-y);
    else
    printf("%d/n", y-x);
    }

    return 0;
    }

    ReplyDelete
  4. where is the condition for " input is not greater than 2^32 " ???

    ReplyDelete
    Replies
    1. we need long long int for 2^32.
      2^32 = 4294967296. int range is -32767, +32767 .So, int not capable of containing 2^32. but long long int rang is −9223372036854775807, +9223372036854775807.
      thats why we have to use long long int for 2^32.

      Delete
  5. #include
    int main()
    {
    int i,j,k,diff;
    for(k=0;k>=0;k++)
    {
    scanf("%d",&i);
    scanf("%d",&j);
    printf("\n");
    if(i<j)
    {
    diff=j-i;
    printf("%d",diff);
    printf("\n");
    }

    }
    return 0;
    }
    if i make this code,then whatis the prblm?

    ReplyDelete
  6. when i use this code..
    #include
    #include
    int main()
    {
    int a,b,c;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
    c=abs(a-b);
    printf("%d\n",c);
    }
    return 0;
    }
    it shows wrong ans in uva what's the problem here.

    ReplyDelete
  7. why I can not run in cmd this file what is problem

    ReplyDelete