‹ 上一题 下一题 ›

g5-04153. GESP-5级-2023-09-单选-第05题 未做

1000 ms 256 MB 测试点 ? GESPGESP-52023-09单选客观题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;
}
  • A. sIn[sIn.length() - 1] + sReverse(sIn.substr(0, sIn.length() - 1));
  • B. sIn[0] + sReverse(sIn.substr(1, sIn.length() - 1));
  • C. sReverse(sIn.substr(0, sIn.length() - 1)) + sIn[sIn.length() - 1];
  • D. sReverse(sIn.substr(1, sIn.length() - 1)) + sIn[sIn.length() - 1];
未选择
输入
输出

            
答案