Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

i cant find why my code is not accepted it is giving wrong anwser but it is stasifying all inputs

$
0
0
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    while(t--)
    {
        char s[1002];
        cin>>s;
        int l=strlen(s);
        int i,j,k,flag=-1;
        if(l%2==0)
        {
            i=(l/2)-1;
            j=(l/2);
            while(i>=0 && j<l)
            {
                if(s[i]==s[j])
                {
                    i--;
                    j++;
                    flag=1;
                }
                else
                {
                    k=0;
                    while(k<=i && j<l)
                    {
                        if(s[k]==s[j])
                        {
                            k++;
                            j++;
                            flag=1;
                        }
                        else
                        {
                            flag=0;
                            break;
                        }
                    }
                    i=-1;
                    j=l;
                }
            }
        }
        else
        {
            flag=0;
            i=(l/2)-1;
            j=(l/2)+1;
            while(i>=0 && j<l)
            {
                if(s[i]==s[j])
                {
                    i--;
                    j++;
                    flag=1;
                }
                else
                {
                    flag=0;
                    break;
                }
            }
            if(flag==0)
            {
                i=0;
                j=(l/2)+1;
                while(i<(l/2) && j<l)
                {
                    if(s[i]==s[j])
                    {
                        i++;
                        j++;
                        flag=1;
                    }
                    else
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
        if(flag==1)
        cout<<"YES"<<endl;
        else if(flag==0)
        cout<<"NO"<<endl;

    }
    return 0;
}

Viewing all articles
Browse latest Browse all 39796

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>