Advertisement
Spocoman

04. Reverse Array of Strings

Nov 17th, 2023
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int MAX_SIZE = 99;
  7.     string arr[MAX_SIZE]{};
  8.    
  9.     int arrSize;
  10.     cin >> arrSize;
  11.  
  12.     for (int i = 0; i < arrSize; i++) {
  13.         cin >> arr[i];
  14.     }
  15.  
  16.     string x;
  17.  
  18.     for (int i = 0; i < arrSize / 2; i++) {
  19.         x = arr[i];
  20.         arr[i] = arr[arrSize - (i + 1)];
  21.         arr[arrSize - (i + 1)] = x;
  22.     }
  23.  
  24.     for (int i = 0; i < arrSize; i++) {
  25.     cout << arr[i] << ' ';
  26.     }
  27.  
  28.     cout << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement