I am DARSHAN JAIN.
I am solving a problem (CODE :- PALL01), and I successfully did it,
but an issue arises while submitting I am getting “WRONG ANSWER”.
I randomly checked all the possible TEST CASES, and all comes as per the required output.
please help me regarding this.
I am solving it for more than 24 hours but did not understand that issue.
I AM SENDING A COPY OF MY CODE IN ATTACHMENTS PLESE HELP.
`#include
using namespace std;
int main()
{
int t,n,r,i,flag;
int a[5];
cin>>t;
while(t>0)
{
cin>>n;
–t;
int lst=0;
while(n>0)
{
r=(n%10);
n=(n/10);
a[lst]=r;
++lst;
}
cout<<"len= "<<lst<<endl;
for(i=0;i<lst;++i)
{
if(a[i]==a[lst-i-1]);
else if(a[i]!=a[lst-i-1])
{
cout<<"loses"<<endl;
break;
}
}
if(a[i]==a[lst-i-1])
cout<<"wins"<<endl;
}
return 0;
}
`
Try this code:
#include
using namespace std;
int main()
{
int t, n, r, i, flag;
int a[5];
cin >> t;
while (t > 0)
{
cin >> n;
--t;
int lst = 0;
while (n > 0)
{
r = (n % 10);
n = (n / 10);
a[lst] = r;
++lst;
}
cout << "len= " << lst << endl;
for (i = 0; i < lst; ++i)
{
if (a[i] == a[lst - i - 1])
;
else if (a[i] != a[lst - i - 1])
{
cout << "loses" << endl;
break;
}
}
if (i == lst)
cout << "wins" << endl;
}
return 0;
}
The question is simply asking for check if the number is palindrome or not, the code you have written is a little too complex for this simple question , you can try a different approach , I have attached my program for the question for your reference:-
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int tempx=n;
int temp=0;
int rev=0;
while(n>0)
{
temp=n%10;
rev=rev*10+temp;
n=n/10;
}
if(rev==tempx)
cout<<"wins"<<endl;
else
cout<<"loses"<<endl;
}
}
1 Like