Skip to main content

Cats and a Mouse Hackerrank Solution in C


#include<stdio.h>
int main()
{
int n,i,a,b,c,d1,d2;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(a>c)
{
d1=a-c;
}
else if(c>a)
{
d1=c-a;
}
else if(a==c)
{
d1=a-c;
}
if(b>c)
{
d2=b-c;
}
else if(c>b)
{
d2=c-b;
}
else if(b==c)
{
d2=c-b;
}
if(d1>d2)
{
printf("Cat B\n");

}
else if(d2>d1)
{
printf("Cat A\n");
}
else
{
printf("Mouse C\n");
}
}
return 0;
}

Comments

Popular posts from this blog

Breaking the Records Hackerrank solution in C

#include< stdio.h > int main() { int n,i,a[ 1000 ],x= 0 ,mn= 0 ; scanf( "%d" ,&n); for (i= 0 ;i<n;i++) { scanf( "%d" ,&a[i]); } int min=a[ 0 ],max=a[ 0 ]; for (i= 0 ;i<n;i++) { if (min>a[i]) { min=a[i]; mn++; } } for (i= 0 ;i<n;i++) { if (max<a[i]) { max=a[i]; x++; } } printf( "%d %d" ,x,mn); return 0 ; }