你给我的代码错了请重新用c++写一下输入格式第一行输入一个初始字符串s由大写英文字母组成n。第二行输入。输出格式输出复制翻转生成的字符串中第n位的字符。样例【样例 1 输入】HONGHE15【样例 1 输出】N【样例 2 输入】MZYZ31【样例 2 输出】Z数据范围与提示【样例 1 解释】输入初始字符串HONGHE操作1次变成HONGHEEHGNOH操作2次变成HONGHEEHGNOHHONGH
以下是重新用C++编写的代码:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int n;
cin >> s >> n;
int m = s.size();
while (m < n) {
string temp = s;
reverse(temp.begin(), temp.end());
s += temp;
m += temp.size();
}
cout << s[n-1] << endl;
return 0;
}
注意:在使用这段代码之前,需要包含 <iostream> 和 <string> 头文件。
原文地址: https://www.cveoy.top/t/topic/hF7n 著作权归作者所有。请勿转载和采集!