Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10.     int testCases;
  11.     cin >> testCases;    
  12.    
  13.     for(int i = 0; i < testCases; i++) {
  14.         string tab;
  15.         cin >> tab;
  16.         int tabSize = tab.size();
  17.         if(tab.size() % 2 != 0) {
  18.             cout << -1 << endl;
  19.             continue;
  20.         }
  21.         int counter = 0;
  22.         for(int j = 0; j < tabSize / 2; j++) {
  23.             for(int k = tabSize / 2 + counter; k < tabSize; k++) {
  24.                 if(tab[j] == tab[k]) {
  25.                     swap(tab[tabSize / 2 + counter], tab[k]);
  26.                     counter++;
  27.                     break;
  28.                 }
  29.             }      
  30.         }
  31.         cout << tabSize / 2 - counter << endl;
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement