Namespaces
Variants
Views
Actions

Help:Contents

From cppreference.com
  1. include<iostream>
  2. include<string>

using namespace std; int lumber(int a[], int n); int main(){ int t; cin >> t; int a[100]; int res = 0;

for (int j = 0; j < t; j++){ for (int i = 0; i < 10; i++) { cin >> a[i]; }

res = lumber(a, 10); cout << "Lumberjacks:\n"; if (res == 0){ cout << "Ordered\n"; } else{ cout << "Unordered\n"; } }

return 0; } int lumber(int a[], int n) { int res = 0; for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ if ((a[i]<a[j]) && (a[j + 1]>a[j + 2])){ if (a[i] == a[j]) swap(a[i], a[j]); res++;

}


else if ((a[i]<a[j]) && (a[i + 2]>a[j + 2])){ if (a[i] == a[j]) swap(a[i], a[j]); res--;


}


} } return res;

}