#include using namespace std; int length, k = 0, shift = 0; int * arr0 = NULL; int * arr1 = NULL; char ch; string temp; // This assignment is worth 5 points. // -1 for not implmenting excess input check or automatic 0 fill. int main() { cout << "Enter the array length: "; cin >> length; cin.ignore(); arr0 = new int[length]; arr1 = new int[length]; cout << "First array: "; do // Bring in the first array { cin >> arr0[k]; k++; ch = cin.get(); } while(ch != '\n' && k < length); if(ch != '\n' && k == length) getline(cin, temp); else if(ch == '\n' && k < length) for(k; k < length; k++) arr0[k] = 0; k = 0; cout << "Second array: "; do // Bring in the second array { cin >> arr1[k]; k++; ch = cin.get(); } while(ch != '\n' && k < length); if(ch != '\n' && k == length) getline(cin, temp); else if(ch == '\n' && k < length) for(k; k < length; k++) arr1[k] = 0; k = 0; while(k < length && shift < length) { // Use modulus to wrap around your index while(arr0[k] == arr1[(k+shift) % length] && k < length) k++; // Number match check happens in nested loop if(k < length) { // Check if the next shift works instead k = 0; shift++; } // If k reaches length, then every value has been matched } if(shift < length) cout << "Shift by " << shift << endl; else cout << "Not a shift!" << endl; return 0; }