Which testcase is failing?

This is my solution to the problem:
#include

using namespace std;

void Shop(int Aayush, int Harshit)

{

int oddcount=1, i=1;

int evencount=2, j=1;

while (oddcount<=Aayush)

{

	oddcount+=2;

	i++;
}

while (evencount<=Harshit)

{

	evencount+=2;
	j++;
}
if (i>j)
{
	cout<<"Aayush"<<endl;
}
else
{
	cout<<"Harshit"<<endl;
}

}

int main()

{

int T;
cin>>T;
int Aayush;
int Harshit;
while (T--)
{
	cin>>Aayush>>Harshit;
	Shop(Aayush,Harshit);
}
return 0;

}

But it always fails 4th testcase. Why?

Hi @eragoncube_54c345cd154261dd Madhav
Refer :
#include
using namespace std;
void Shop(int Aayush, int Harshit)
{
int a=0; // for checking number of purchase by Ayush
int b=0; // for checking number of purchase by Harshit
int oddcount=0, i=1;
int evencount=0, j=2;
while (oddcount<=Aayush)
{
if((oddcount+i)<=Aayush){
oddcount=oddcount + i;
i=i+2;
a=a+1;
}
else{
break;
}
}
while (evencount<=Harshit)
{
if((evencount+i)<=Harshit){
evencount=evencount + j;
j=j+2;
b=b+1;
}
else{
break;
}
}
if (a>b)
{
cout<<“Aayush”<<endl;
}
else
{
cout<<“Harshit”<<endl;
}
}
int main()
{
int T;
cin>>T;
while (T–)
{
int Aayush;
int Harshit;
cin>>Aayush>>Harshit;
Shop(Aayush,Harshit);
}
return 0;
}

I also send the solution on your whatsapp

hi @eragoncube_54c345cd154261dd,
refer here https://ide.codingblocks.com/s/660264
And do a dry run on paper

1 Like