Click
Here to go back to the homepage.
Permuted Arithmetic Sequence Solution:
#include <bits/stdc++.h>
using namespace std;
bool isarithmetic(vector<int> v){
int sumdiff = v[1] - v[0];
for(int i = 1; i < v.size(); i++){
if(v[i] - v[i - 1] == sumdiff){
continue;
}
return false;
}
return true;
}
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int cases;
cin >> cases;
while(cases--){
int vals;
cin >> vals;
vector<int> v(vals);
for(int &i: v){
cin >> i;
}
if(isarithmetic(v)) {
cout << "arithmetic" << endl;
continue;
}
sort(v.begin(), v.end());
bool permutedarithmetic = isarithmetic(v);
if(!permutedarithmetic){
cout << "non-arithmetic" << endl;
} else {
cout << "permuted arithmetic" << endl;
}
}
return 0;
}