/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'int main()':
foo.cc:26:10: error: expected ',' or ';' before 'int'
   26 |          int tmp = v[k];
      |          ^~~
foo.cc:30:21: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   30 |          v[k + 2] = tmp;
      |                     ^~~
      |                     tm

Code

// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while(t--){
     int n;
     cin >> n;
     vector<int>v(n);
     
     for(int i = 0 ; i < n; i++){
         v[i] = i + 1;
     }
     
     if(n % 2 == 0){
         for(int i = 0 ; i < n ; i+=2){
         swap(v[i] , v[i + 1]);
         }
     }
     else{
         for(int i = 0 ; i < n - 3 ; i++){
             swap(v[i] , v[i + 1]);
         }
         int k = n - 3
         int tmp = v[k];
         
         v[k]  = v[k + 1];
         v[k + 1] = v[k + 2];
         v[k + 2] = tmp;
       
       
     }
     
    for(int i = 0 ; i < n ; i++){
        cout << v[i]<<" "; 
    }
    cout <<endl;
      
  }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1210 A. Smallest Permutation
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 21:39:50
Judged At
2025-07-14 21:39:50
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes