HDU 2019 数列有序!(水题)

题目链接:HDU 2019 数列有序!
在这里插入图片描述

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;
typedef long long ll;
const int maxn = 110;
const int INF = 0x3f3f3f3f;
int a[maxn];

int main()
{
	int n,x;
	while(scanf("%d%d",&n,&x)!=EOF&&n+x)
	{
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		
		int pos = upper_bound(a,a+n,x)-a;
		
		for(int i=0;i<pos;i++)
			printf("%d ",a[i]);
		printf("%d",x);
		for(int i=pos;i<n;i++)
			printf(" %d",a[i]);
		printf("\n");
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/89810896