Вывести строку в обратном направлении — C++(Си)

#include <iostream>
#include <conio.h>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main()
{
     string s;
     cin >> s;
     reverse(s.begin(),s.end());
     cout << s;
     getch();
}

Результат работы программы

Следующий вариант

#include <iostream>
#include <conio.h>
#include <string>
#include <stack>
 
using namespace std;
 
int main()
{
     string s;
     stack<string> st;
     while(cin >> s)
         st.push(s);
     while(!st.empty())
     {
           cout << st.top() << ' ';
           st.pop();
     }
     getch();
}

Для окончания нажать ctrl+Z

Следующий вариант

С использованием файлов

#include <fstream>
#include <string>
#include <stack>
 
using namespace std;
 
ifstream cin("input.txt");
ofstream cout("output.txt");
 
int main()
{
     string s;
     stack<string> st;
     while(cin >> s)
         st.push(s);
     while(!st.empty())
     {
           cout << st.top() << ' ';
           st.pop();
     }
}

One Thought to “Вывести строку в обратном направлении — C++(Си)”

  1. Jon

    Wow, fantastic blog format! How lengthy have you been running a blog for?

    you made running a blog glance easy. The full glance of your site is wonderful, as smartly as the
    content! You can see similar here sklep online

Leave a Comment