Advertisement
Spocoman

1. Reverse String

Jan 9th, 2024
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string s;
  9.     getline(cin, s);
  10.  
  11.     stack<char> chars;
  12.  
  13.     for (int i = 0; i < s.length(); i++) {
  14.         chars.push(s[i]);
  15.     }
  16.  
  17.     while (!chars.empty()) {
  18.         cout << chars.top();
  19.         chars.pop();
  20.     }
  21.  
  22.     cout << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement