program doesn't work on codechef but works on my machine

Problem - LOSTMAX
level . beginner
here is the code
"
#include
#include

using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
vector a;
char x;
int n=0;
int temp;
do
{

		cin>>temp;
		a.push_back(temp);
		n++;
		x=getchar();
	} while(x!='\n');
	n--;
	for(int i=0;i<n;i++)
	{
		if(a[i]==n)
		{
			a[i]=0;
		}
		break;
	}
	int y=a[0];
	for(int i=0;i<n;i++)
	{
		if(y<a[i])
		{
			y=a[i];
		}
	}
	cout<<endl<<y;
}
return 0;

}
"
thanks for help in advance

@soumilkanwal80 I guess you misplaced the break statement in your code. Instead placing it inside if block, you mistakenly put it outside if block at line no 30. And maximum value could be the last value so run loop till n+1, your’s accepted code with modifications solution link .