You are viewing a single comment's thread. Return to all comments →
using namespace std;
typedef vector vi; typedef vector vvi;
typedef long long int ll; const ll mx= LLONG_MAX; const ll mn= LLONG_MIN; const ll MOD= 1e9+7;
int main() {
GET_FASTER; int t; cin>> t; string s; ig; while(t--){ cin>> s; if(s.size()%2==0){ int l=s.size()/2,cnt=0; vi v1(27+1,0),v2(27+1,0); for(int i=0; i<l; i++){ v1[(s[i]-96)]++; v2[(s[i+l]-96)]++; } for(int i=0; i<28; i++){ cnt+=(abs(v1[i]- v2[i])); } cout<< cnt/2<< endl; } else{ cout<< "-1"<< endl; } } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
include
using namespace std;
typedef vector vi; typedef vector vvi;
define pb push_back
define all(c) (c).begin(),(c).end()
define print(c) for(auto i: c){cout<< i <<" ";}
define endl '\n'
define ig cin.ignore()
define PI 3.1415926535897932384626
define mp make_pair
define fi first
define se second
define GET_FASTER ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long int ll; const ll mx= LLONG_MAX; const ll mn= LLONG_MIN; const ll MOD= 1e9+7;
int main() {
}