Codechef : Problem name " The Block Game " solution in C#
=============================Solution=================================
using System;
public class Test
{
public static void Main()
{
int t=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<t;i++){
//string[] array=Console.ReadLine().Split(' ');
string X=Console.ReadLine();
bool isPallindrome=false;
int k,j;
for(k=0,j=X.Length-1 ; k<=(X.Length-1)/2 && j>=(X.Length-1)/2 ; k++,j--)
{
if(X[k]=='0')
{
isPallindrome=false;
}
if(X[k]==X[j])
{
isPallindrome=true;
}
else if(X[k] != X[j])
{
isPallindrome=false;
break;
}
}
if(isPallindrome)
Console.WriteLine("wins");
else if(isPallindrome==false)
Console.WriteLine("loses");
}
}
}
Comments
Post a Comment