代码:
using System;
namespace cccc
{
class Program
{
static void Main(string[] args)
{
//得到有序的数组
string str = Console.ReadLine();
string[] sttr = str.Split(" ");
int[] a = new int[sttr.Length];
int m = a.Length - 1;
for (int i = 0; i < sttr.Length; i++)
{
int n = Convert.ToInt32(sttr[i]);
a[i] = n;
}
int x = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<a.Length-1;i++)
{
if(x>=a[i] && x<=a[i+1])
{
m = i;
break;
}
}
if (x<a[0])
{
m = -1;
}
int[] b = new int[a.Length + 1];
for(int i=0;i<m+1;i++)
{
b[i] = a[i];
}
b[m + 1] = x;
for(int i=m+1;i<a.Length;i++)
{
b[i + 1] = a[i];
}
foreach (int t in b)
{
Console.Write(t + " ");
}
}
}
}
运行结果: