#include<bits/stdc++.h> using namespace std; int main(){ int tt; cin >> tt; while(tt--){…
- User
#include<bits/stdc++.h> using namespace std;
int main(){ int tt; cin >> tt; while(tt--){ int n; cin >> n; vector a(n); vector b(n); vector<pair<int,int>> v; int count; for(int i=0; i<n; i++){ int p; cin >> p; a[i] = p; }
codefor(int i=0; i<n; i++){ int p; cin >> p; b[i] = p; if(n&1 && (i+1)!=n/2 && a[i] == b[i]){ cout << "-1"; return 0; } } // after input for(int i = 0; i < n; i++){ if(a[i] != b[n-1-i]){ int ix = find(a.begin(),a.end(),b[n-1-i])-a.begin(); swap(a[i],a[ix]); swap(b[i],b[ix]); v.push_back({i,ix}); count++; } } reverse(b.begin(),b.end()); if(a==b){ cout<<count<<"\n"; for(auto i : v){ cout<<i<<"\n"; } } if(tt)cout<<"\n"; } return 0;} why compilation errro
- Assistant
- User
some outputs are wrong corret the code for C. You Soared Afar With Grace time limit per test2 seconds memory limit per test256 megabytes
You are given a permutation a and b of length n ∗ . You can perform the following operation at most n times:
Choose two indices i and j (1≤i,j≤n , i≠j ), swap ai with aj , swap bi with bj . Determine whether a and b can be reverses of each other after operations. In other words, for each i=1,2,…,n , ai=bn+1−i .
If it is possible, output any valid sequence of operations. Otherwise, output −1 .
∗ A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
- Assistant
- User
what does this mean wrong output format Unexpected end of file - int32 expected (test case 6) my test code is not able to output the 8the test case even though my code is correct
- Assistant
- User
maky my code adhere to the input output format also comment where ever you may make the changes #include<bits/stdc++.h> using namespace std; int main(){ int tt; cin >> tt; // Read number of test cases while(tt--){ int n; cin >> n; // Read number of elements
code - Assistant