2024码蹄杯高职组初赛第二场 H题 完美镶嵌点

61 阅读1分钟

码题集OJ-完美镶嵌点 (matiji.net)

思想

我在输入的过程中进行比大小

#include<bits/stdc++.h> 
#define int long long
using namespace std;
vector<int>v;
int flag; 
signed main()
{
		cin.tie(nullptr)->sync_with_stdio(0);	

    int n,x;cin>>n>>x;
    for(int i=0;i<n;i++)
    {
    	int t;cin>>t;
    
    	if(t>x && flag==0)
    	{
    		v.push_back(x);
		    flag=1;
	    }	
		v.push_back(t);
	}
   
   if(flag==0) v.push_back(x);
   for(auto &it:v)
   {
   	cout<<it<<" ";
   }
	return 0;
}

image.png