Palindrome (Problem ID 25)

Dev Skill archived problems can be discussed here.

Palindrome (Problem ID 25)

by Alim14 » Wed Nov 30, 2016 10:52 pm

Why the following code gets WA? Would anyone please help me to figure out. TIA.

Problem Link: http://www.devskill.com/CodingProblems/ViewProblem/25

My Code:

Code: Select all
#include<bits/stdc++.h>
using namespace std;


string s;
int n;
bool check()
{
    int i,j;
    for(i=0,j=n-1;i<=n/2;i++,j--)
    {
        if(s[i]!=s[j]) return 0;
    }
    return 1;
}


int main()
{
    int i,j,k,m,d,test,t=0;
    cin>>test;
    getchar();
    while(test--)
    {
        getline(cin,s);
        n=s.size();
        for(i=0;i<n;i++)
        {
            if(s[i]>='A'&&s[i]<='Z')
                s[i]=s[i]+32;
        }
        if(check()) puts("Yes");
        else puts("No");
        s.clear();
    }
    return 0;
}
 
Posts: 1
Joined: Wed Nov 30, 2016 10:45 pm

Re: Palindrome (Problem ID 25)

by rayhan50001 » Sat Dec 17, 2016 2:14 pm

please use "cin>>s" instead of "getline(cin,s)"
 
Posts: 11
Joined: Tue Oct 25, 2016 6:25 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron