3 条题解

  • 1
    @ 2024-5-1 9:21:48

    很多人会把a[1]跟a[p]做交换,但我偏不这样,我要独树一帜

    已AC,请放心食用

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, minn = 40000, a[205], p;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            if (a[i] < minn)
            {
                minn = a[i];
                p = i;
            }
        }
        cout << p << endl << minn << " ";
        for (int i = 2; i <= n; i++)
        {
            if (i == p)
            {
                cout << a[1] << " ";
                continue;
            }
            cout << a[i] << " ";
        }
        return 0;
    }
    
    • 1
      @ 2023-4-14 21:44:25
      #include<bits/stdc++.h>
      using namespace std;
      int n,a[207],m;
      int main()
      {
          cin>>n;
          for (int i=1;i<=n;i++)
          {
              cin>>a[i];
              if (a[i]<a[m]);
                  m=i;
          }
          cout<<m<<'\n'<<a[m]<<" ";
          for (int i=2;i<=n;i++)
          {
              if (i==m)
                  cout<<a[1]<<" ";
              else
                  cout<<a[i]<<" ";
          }
          return 0;
      }
      • 1
        @ 2023-1-17 22:20:02
        #include<bits/stdc++.h>
        using namespace std;
        int n, a[210], i, mi = INT_MAX, t, p;
        int main()
        {
        	cin >> n;
        	for(i = 1; i <= n; i++){
        		cin >> a[i];
        		//打擂台球最小数,只记录第一个
        		if(a[i] < mi){
        			mi = a[i];
        			p = i;
        		} 
        	}
        	swap(a[1],a[p]);
        	cout << p << endl;
        	for(i = 1; i <= n; i++) cout << a[i] << " ";	
        	return 0;
        }
        
        
        
        • 1

        信息

        ID
        157
        时间
        1000ms
        内存
        16MiB
        难度
        2
        标签
        递交数
        133
        已通过
        78
        上传者