3 条题解

  • 1
    @ 2023-8-16 21:47:10

    挥肠简单的一道题辣👀️

    思路:找到数组中最小值,把最小值跳过输出数组中的各个元素

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n , a[100] , minn = 13454;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] < minn) minn = a[i];
        }
        for (int i = 0; i < n; i++)
        {
            if(a[i] != minn) cout << a[i] << " ";
        }
        return 0;
    }
    
    • 0
      @ 2024-2-16 14:23:12

      思路:vectorerase函数删除

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          vector<int> v;//定义向量
          int n;
          //输入
          cin >> n;
          for (int i = 1;i <= n;i++)
          {
              int t;
              cin >> t;
              v.push_back(t);
          }
          vector<int>::iterator minj = v.begin();//定义送代器
          for (vector<int>::iterator it = v.begin();it != v.end();it++)//遍历向量
          {
              //打擂台求最小值
              if (*minj >= *it)
              {
                  minj = it;
              }
          }
          //删除
          v.erase(minj);
          //输出
          for (int i = 0;i < v.size();i++)
          {
              cout << v[i] << " ";
          }
          return 0;
      }
      
      • 0
        @ 2023-1-17 22:36:13
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int a[110],n,mi;
        	cin >> n;
        	for(int i = 0; i < n; i++){
        		cin >> a[i];
        	}
        	mi = a[0];//查找最小的数
        	for(int i = 1; i < n; i++){
        		if(a[i] < mi){
        			mi = a[i];
        		}
        	} 
        	//输出除了最小数以外的数
        	for(int i = 0; i < n; i++){
        		if(a[i] != mi){
        			cout << a[i] << " ";
        		}
        	} 
        	return 0;
        }
        
        
        
        • 1

        【入门】删除数组的最小数

        信息

        ID
        213
        时间
        1000ms
        内存
        16MiB
        难度
        1
        标签
        递交数
        76
        已通过
        54
        上传者