#include <iostream> #include <string> using namespace std; int main() { string txt; cout << "Enter text that you need to reverse.\n" << "Write without spaces!\n"; cin >> txt; int txtl = txt.length(); do { txtl--; char txrd = txt.back(); cout << txrd; txt.pop_back(); } while (txtl >= 1); }
допустим, в приложении ты реализуешь данный алогоритм, ты так же будешь пользователя просить ввести текст без пробелов ?? я б такого разработчика послал и удалил бы приложение нахуй
#include <iostream> #include <string> using namespace std; int main() { string text = "Hello, world!"; int i, j, tmp; j = text.length() - 1; for(i = 0, j; i <= j; i++, j--) { tmp = text[i]; text[i] = text[j]; text[j] = tmp; } cout << text; } Код #include <iostream> #include <string> using namespace std; int main() { string text = "Hello, world!"; int i, j, tmp; j = text.length() - 1; for(i = 0, j; i <= j; i++, j--) { tmp = text[i]; text[i] = text[j]; text[j] = tmp; } cout << text; }