4 条题解

  • 1
    @ 2024-2-16 14:25:00
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        //1.用向量输入
        vector<int> v;
        int n,y;
        cin >> n;
        for (int i = 1;i <= n;i++)
        {
            int t;
            cin >> t;
            v.push_back(t);
        }
        cin >> y;
        //2.找最大值的送代器
        vector<int>::iterator maxj = v.begin();
        for (vector<int>::iterator it = v.begin();it != v.end();it++)
        {
            if (*maxj <= *it)
            {
                maxj = it;
            }
        }
        //3.插入
        v.insert(maxj + 1,y);//注意不要写成v.insert(maxj,y);
        //4.输出
        for (int i = 0;i < v.size();i++)
        {
            cout << v[i] << " ";
        }
        return 0;
    }
    
    • 1
      @ 2023-8-17 21:13:03

      很简单的题目👀️

      上代码🎉️

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n , a[100] , y , maxx = 0;
          cin >> n;
          for (int i = 0; i < n; i++) 
          {
              cin >> a[i];
              if (a[i] > maxx) maxx = a[i];//最大数值
          }
          cin >> y;
          for (int i = 0; i < n; i++)
          {
              cout << a[i] << " ";//先输出数组中的数
              if (a[i] == maxx)  cout << y << " ";//如果是最大数,在后面插入y
          }
          return 0;
      }
      

      AC,放心食用

      • 0
        @ 2023-5-3 17:19:36
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n, x;
            cin >> n;
            int a[n + 1];
            cin >> a[1];
            int maxx = a[1];
            for (int i = 2; i <= n; i++)
            {
                cin >> a[i];
                maxx = max(maxx, a[i]);
            }
            cin >> x;
            for (int i = 1; i <= n; i++)
            {
                cout << a[i] << " ";
                if (a[i] == maxx)
                {
                    cout << x << " ";
                }
            }
            return 0;
        }
        
        • 0
          @ 2023-1-17 22:45:26
          #include<bits/stdc++.h>
          using namespace std;
          int a[110],n,p,ma = INT_MIN,y,i;
          int main()
          {
          	cin >> n;
          	//找出最大数的下标
          	for(i = 1; i <= n; i++){
          		cin >> a[i];
          		if(a[i] > ma){
          			ma = a[i];
          			p = i;
          		}
          	} 
          	cin >> y;
          	//从最大的数开始所有的数后移一位
          	for(i = n; i > p; i--){
          		a[i+1] = a[i];
          	} 
          	//插入这个数
          	a[i+1] = y;
          	n++;
          	//输出结果
          	for(i = 1; i <= n; i++) cout << a[i] << " "; 
          	return 0;
          }
          
          • 1

          【入门】在最大数后面插入一个数

          信息

          ID
          214
          时间
          1000ms
          内存
          16MiB
          难度
          1
          标签
          递交数
          68
          已通过
          48
          上传者