5 条题解

  • 1
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e7+10;
    const int INF=0x3f3f3f3f;
    int a[N],f;
    int main()
    {
    	int n,m;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    	}
    	cin>>m;
    	a[n+1]=m;
    	sort(a+1,a+n+2);
    	for(int i=1;i<=n+1;i++)
    	{
    		cout<<a[i]<<" ";
    	}
    	return 0;
    }
    

    最简单题解

    • 1
      @ 2023-4-15 15:17:40
      #include<iostream>
      using namespace std;
      const int N=1e5+1;
      int n,x,a[N],k=1;
      int main(){
      	cin>>n;
      	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      	cin>>x;
      	for(int i=1;i<=n;i++){
      		if(a[i-1]<x&&x<=a[i]){
      			cout<<x<<" ";
      			k=0;
      		}
      		cout<<a[i]<<" ";
      	}
      	if(k)cout<<x;
      	return 0;
      }
      
      • 0

        插入排序:我懂

        #include <bits/stdc++.h>
        using namespace std;
        const int N=1e7+10;
        const int INF=0x3f3f3f3f;
        int a[N],f;
        int main()
        {
        	int n,m;
        	cin>>n;
        	for(int i=1;i<=n;i++)
        	{
        		cin>>a[i];
        	}
        	cin>>m;
        	for(int i=1;i<=n;i++)
        	{
        		if((m<=a[i] && f==0))
        		{
        			cout<<m<<" ";
        			f=1;
        		}
        		cout<<a[i]<<" ";
        	} 
        	if(f==0)
        	{
        		cout<<m;
        	}
        	return 0;
        }
        
        
        • 0
          @ 2023-5-29 17:47:48
          #include <iostream>
          #include <stack>
          #include <cmath>
          #include <vector>
          #include <string.h>
          #include <queue>
          #include <stdio.h>
          #include <iomanip>
          #include <cstdio>
          #include <algorithm>
          #define int long long
          using namespace std;
          const int N = 1e5 + 10;
          const int INF = 0x3f3f3f3f;
          int a[N];
          signed main()
          {
              int n;
              cin >> n;
              for(int i = 1; i <= n; i++)
              {
                  cin >> a[i];
              }
              a[n + 1] = INF;
              a[0] = -INF;
              int x;
              bool flag = 0;
              cin >> x;
              for(int i = 1; i <= n; i++)
              {
                  if(x > a[i - 1] && x <= a[i])
                  {
                      cout << x << " ";
                      flag = 1;
                  }
                  cout << a[i] << " ";
              }
              if(flag == 0)
              {
                  cout << x << endl;
              }
          	return 0;
          }
          
          • 0
            @ 2023-2-2 14:39:57

            以一己之力将难度8变成了难度7

            #include <iostream>
            #include <stack>
            #include <cmath>
            #include <vector>
            #include <string.h>
            #include <queue>
            #include <stdio.h>
            #include <iomanip>
            #include <cstdio>
            #include <algorithm>
            #define int long long
            using namespace std;
            const int N = 1e5 + 10;
            const int INF = 0x3f3f3f3f;
            int a[N];
            signed main()
            {
                int n;
                cin >> n;
                for(int i = 1; i <= n; i++)
                {
                    cin >> a[i];
                }
                a[n + 1] = INF;
                a[0] = -INF;
                int x;
                bool flag = 0;
                cin >> x;
                for(int i = 1; i <= n; i++)
                {
                    if(x > a[i - 1] && x <= a[i])
                    {
                        cout << x << " ";
                        flag = 1;
                    }
                    cout << a[i] << " ";
                }
                if(flag == 0)
                {
                    cout << x << endl;
                }
            	return 0;
            }
            
            • 1

            信息

            ID
            1025
            时间
            1000ms
            内存
            128MiB
            难度
            5
            标签
            递交数
            243
            已通过
            100
            上传者