#3323. [GESP202309 五级 C++] 第 5 题

[GESP202309 五级 C++] 第 5 题

下面C++代码以递归方式实现字符串反序,横线处应填上代码是( )。

//字符串反序
#include <iostream>
#include <string>
using namespace std;
string sReverse(string sIn) {
    if (sIn.length() <= 1) {
        return sIn;
    } else {
        return _________ // 此处填写代码
    }
}
int main() {
    string sIn;
    cin >> sIn;
    cout << sReverse(sIn) << endl;
    return 0;
}

{{ select(1) }}

  • sIn[sIn.length() - 1] + sReverse(sIn.substr(0, sIn.length() - 1));
  • sIn[0] + sReverse(sIn.substr(1, sIn.length() - 1));
  • sReverse(sIn.substr(0, sIn.length() - 1)) + sIn[sIn.length() - 1];
  • sReverse(sIn.substr(1, sIn.length() - 1)) + sIn[sIn.length() - 1];