fork download
  1. /*
  2.   Cred : SunnyYeahBoi
  3.   It's my last chance (⌐■_■)
  4.   Problem :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12. #define double long double
  13. #define endl "\n"
  14. #define NAME "a"
  15.  
  16. const int MAXN = 1e6 + 5;
  17. const int inf = 1e18;
  18. const int MOD = 1e9 + 7;
  19.  
  20. void FileInput(){
  21. if(fopen(NAME".inp" , "r") == NULL)
  22. freopen(NAME".inp" , "w" , stdout);
  23. freopen(NAME".inp" , "r" , stdin);
  24. freopen(NAME".out" , "w" , stdout);
  25. }
  26.  
  27. // tạo mảng a gồm 10 phần tử
  28. // kdl tên_mảng[số_phần_tử];
  29.  
  30. /*
  31.   Lưu ý khi sử dụng mảng:
  32.   - Mảng bắt đầu từ phần tử 0
  33.   1 -> 10 , a[MAXN]
  34.   - truy cập vào phần tử i mảng: a[i]
  35.   a[5] , a[10] , a[i] , a[n]
  36.   - trong mảng không có phần tử âm
  37.   - chỉ sử dụng những phần tử đã khai báo
  38. */
  39.  
  40. const int N = 1e6 + 5;
  41. int a[N];
  42. int n;
  43.  
  44. void solve(){
  45. cin >> n;
  46. for(int i = 1 ; i <= n ; i++)
  47. cin >> a[i];
  48.  
  49. reverse(a + 1 , a + 1 + n);
  50. // a đang chỉ vào vị trí 0
  51. // a + 1 chỉ vào vị trí 0 + 1 = 1
  52. // a + 1 + n chỉ vào vị trí 0 + 1 + n = n
  53. // a + 1 biên bên trái
  54. // a + 1 + n biên bên phải
  55.  
  56. for(int i = 1 ; i <= n ; i++)
  57. cout << a[i] << " ";
  58. }
  59.  
  60. int32_t main(){
  61. FileInput();
  62. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  63. int t = 1;
  64. // cin >> t;
  65. while(t--)
  66. solve();
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty