c++字符串操作中插入字符,为何我的输出后面跟着乱码 10
输出如下代码如下#include<iostream>#include<string>usingnamespacestd;intmain(){intT;cin>>T;for...
输出如下
代码如下
#include<iostream>
#include<string>
using namespace std;
int main()
{
int T;
cin >> T;
for (int i = 0; i<T; i++)
{
string s1;
char s2;
int pos;
cin >> s1 >> s2;
for (pos = 0; pos<s1.size(); pos++)
{
if (s2 <= s1[pos]) break;
}
for (int j = s1.size(); j>pos; j--)
{
s1[j] = s1[j - 1];
}
s1[pos] = s2;
cout << s1 << endl;
}
return 0;
} 展开
代码如下
#include<iostream>
#include<string>
using namespace std;
int main()
{
int T;
cin >> T;
for (int i = 0; i<T; i++)
{
string s1;
char s2;
int pos;
cin >> s1 >> s2;
for (pos = 0; pos<s1.size(); pos++)
{
if (s2 <= s1[pos]) break;
}
for (int j = s1.size(); j>pos; j--)
{
s1[j] = s1[j - 1];
}
s1[pos] = s2;
cout << s1 << endl;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询