Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <climits>
- #include <cstdlib>
- using namespace std;
- int nonEqual(vector <string> checkAr, int checkInd) {
- int ans = 0;
- for (int i = 0; i < checkAr.size(); i++) {
- if (checkAr[i] == checkAr[checkInd]) continue;
- int curAns = 0;
- for (int j = 0; (checkAr[i] != checkAr[checkInd]) && (j < checkAr[i].size()); curAns++, j++)
- checkAr[i].push_back(checkAr[i][0]),
- checkAr[i].erase(checkAr[i].begin(), checkAr[i].begin() + 1);
- if (checkAr[i] != checkAr[checkInd]) {
- cout << "-1";
- exit(0);
- }
- ans += curAns;
- }
- return ans;
- }
- int main() {
- int n;
- cin >> n;
- vector <string> ar(n);
- for (int i = 0; i < ar.size(); i++)
- cin >> ar[i];
- int ans = INT_MAX;
- for (int i = 0; i < ar.size(); i++)
- ans = min(ans, nonEqual(ar, i));
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement