#include <iostream>
#include <string>
using namespace std;
string Reverse(string str);
int main()
{
cout << "Enter some strings: " << endl;
string s;
while (true) {
cout << "? ";
cin >> s;
if (cin.fail() || s.empty()) break;
cout << Reverse(s) << endl;
}
return 0;
}
string Reverse(string str) {
// simple case
if (str.empty()) return string("");
// recursive decomposition
string::size_type len = str.length();
return str.substr(len-1) + Reverse(str.substr(0, len-1));
}
reverse string using recursion
最新推荐文章于 2020-12-07 11:12:21 发布