fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define name "EZSWAP"
  5. const int MAXN = 2e5+5;
  6.  
  7. int n, a[MAXN];
  8.  
  9. void setIO(){
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0); cout.tie(0);
  12. if (fopen(name".inp", "r")){
  13. freopen(name".inp", "r", stdin);
  14. freopen(name".out", "w", stdout);
  15. }
  16. }
  17.  
  18. void inp(){
  19.  
  20. }
  21.  
  22.  
  23. void solve(){
  24. cin >> n;
  25. for (int i = 1; i<=n; i++){
  26. cin >> a[i];
  27. }
  28.  
  29. swap(a[1], a[n]); // Câu lệnh swap hoán đổi vị trí của a[1] (đầu) và a[n] (cuối)
  30.  
  31. for (int i = 1; i<=n; i++){
  32. cout << a[i] << " ";
  33. }
  34. }
  35.  
  36. int main(){
  37. setIO(); // Nhập xuất file
  38. inp(); // Nhập dữ liệu (có nội dung trong chương trình con hay không cũng được)
  39. solve(); // Giải quyết vấn đề của đề bài đưa ra
  40. }
Success #stdin #stdout 0.01s 5272KB
stdin
5
10 20 30 40 50
stdout
50 20 30 40 10