首页 > 代码库 > 杭电2016数列有序

杭电2016数列有序

#include<iostream>
using namespace std;
int main()
{
  int n,m,t = 0;
  int a[110], b[110];
  while (cin >>n>>m)
  {
    if (n == 0 && m ==0)//讨论零的情况
      {
        break;
      }
    else
    {
      for (int i = 0; i < n; i++)//输入数组值
      cin >> a[i];
      for (int i = 0; i < n; i++)//把数组a的值赋给b,直到m赋给了b就跳出循环,再开始后面的复制赋值
        {
          if (m>a[i])
          b[i] = a[i];
      else
        {
          b[i] = m;
          break;
        }
          t++;
     }
    for (int i = t; i < n; i++)
    b[i + 1] = a[i];
    for (int i = 0; i < n; i++)
    cout << b[i] << " ";//最后一个数后面不能有空格,所以要分开输出
    cout << b[n] << endl;
    t = 0;
    }
  }
  return 0;
}

杭电2016数列有序