Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int testCases;
- cin >> testCases;
- for(int i = 0; i < testCases; i++) {
- string tab;
- cin >> tab;
- int tabSize = tab.size();
- if(tab.size() % 2 != 0) {
- cout << -1 << endl;
- continue;
- }
- int counter = 0;
- for(int j = 0; j < tabSize / 2; j++) {
- for(int k = tabSize / 2 + counter; k < tabSize; k++) {
- if(tab[j] == tab[k]) {
- swap(tab[tabSize / 2 + counter], tab[k]);
- counter++;
- break;
- }
- }
- }
- cout << tabSize / 2 - counter << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement