Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <climits>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int nonEqual(vector <string> checkAr, int checkInd) {
  9. int ans = 0;
  10.  
  11. for (int i = 0; i < checkAr.size(); i++) {
  12. if (checkAr[i] == checkAr[checkInd]) continue;
  13.  
  14. int curAns = 0;
  15. for (int j = 0; (checkAr[i] != checkAr[checkInd]) && (j < checkAr[i].size()); curAns++, j++)
  16. checkAr[i].push_back(checkAr[i][0]),
  17. checkAr[i].erase(checkAr[i].begin(), checkAr[i].begin() + 1);
  18.  
  19. if (checkAr[i] != checkAr[checkInd]) {
  20. cout << "-1";
  21. exit(0);
  22. }
  23.  
  24. ans += curAns;
  25. }
  26.  
  27. return ans;
  28. }
  29.  
  30. int main() {
  31. int n;
  32. cin >> n;
  33.  
  34. vector <string> ar(n);
  35. for (int i = 0; i < ar.size(); i++)
  36. cin >> ar[i];
  37.  
  38. int ans = INT_MAX;
  39. for (int i = 0; i < ar.size(); i++)
  40. ans = min(ans, nonEqual(ar, i));
  41.  
  42. cout << ans;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement