#include <iostream>
using namespace std;
int main()
{ int n,m;
while(cin>>n>>m&&n+m)
{ int t[105]={0};
bool flag=true;
for(int i=0;i<=n;++i){
cin>>t[i];
if(m<t[i]&&flag){
t[i+1]=m;
swap(t[i],t[i+1]);
flag=false;
i++;
}
}
for(int i=0;i<n;++i)
cout<<t[i]<<" ";
cout<<t[n]<<endl;
}
return 0;
}
tips:
借鉴了别人的,我自己写的不知道为什么无法换数,难过。差一点把我弄崩了,一直RE,结果是因为第一个for循环没有写i<=n,原先是i<n。以后要注意。
有一些我没有想到的点
1.while(cin>>n>>m&&n+m) 表示m,n不同时为0.
2.swap函数
3.用flag实现一次插入