写题

`#define _CRT_SECURE_NO_WARNINGS

include

include

include

using namespace std;
int main()
{
string input;
int length;
char put;
cin >> length;
cin.ignore();
put = cin.get();
cin.ignore(numeric_limits::max(), '\n');
getline(cin, input);
if (length < input.size())//判断要求字符串长度是否超出限制
{
string str = input.substr(input.size() - length);
cout << str << endl;
return 0;
}
input.insert(0, length - input.size(), put);
cout << input << endl;
return 0;
}`
cin后面跟getline可能会跳过,要加 cin.ignore()来解决

posted @ 2025-07-16 20:05  白底纸板  阅读(4)  评论(0)    收藏  举报