Wrong answer

why I got WA in Lapindromes problem.
problem link


solution->

#include
#include<bits/stdc++.h>
#include
using namespace std;

int main()
{
//cout << “Hello world!” << endl;
int t;
cin>>t;
while(t–)
{
string str;
cin>>str;
int l=str.length(),count=0,x=0,y=0,z=0;
if(l%2==0)
{

    for(int i=0;i<l/2;i++)
    {
        if(str[i]<='z')
        {
            count=count+str[i];
        }

    }
    //cout<<count<<endl;
    for(int i=l/2;i<=l;i++)
    {
        if(str[i]<='z')
            x=x+str[i];
    }
    if(x==count)
    {
        cout<<"YES"<<endl;

    }
    else
        cout<<"NO"<<endl;
    }
    else
    {
        for(int i=0;i<l/2;i++)
    {
        if(str[i]<='z')
        {
            y=y+str[i];
        }

    }
    //cout<<count<<endl;
    for(int i=l/2+1;i<=l;i++)
    {
        if(str[i]<='z')
            z=z+str[i];
    }
    if(y==z)
    {
        cout<<"YES"<<endl;

    }
    else
        cout<<"NO"<<endl;
    }

//cout<<y<<" "<<z;
}
return 0;

}

You are using “t-” in your while statement instead of “t- -”, maybe that is the problem.

1 Like

This should gives compiler error not wrong ans.
Also this is not the case.
Thanks for effort

You are getting wrong answer cause you are playing with numbers instead of characters.
100+102+97 == 97 + 97 + 105 but dfa != aai

Thanks