Search This Blog

Monday, 18 July 2016

HackerEarth - Xsquare And Balanced Strings - (Dynamic Programming)

Xsquare And Balanced Strings (HackerEarth) (Dynamic Programming, Easy)

Solution:-

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

int T,N;
string str ;
int main()
{
cin >> T ;
while(T--)
    {
cin >> str ;
N = str.length() ;
int ans = 0 ;
for(int i=0;i<N;i++)
ans = ans ^ (str[i]-'a') ;

puts(ans == 0 ? "1" : "-1") ;
    }
return 0 ;

}

No comments:

Post a Comment