8 条题解

  • 2
    @ 2022-11-5 13:51:40

    #include<bits/stdc++.h> using namespace std; int f[114514]; int main(){ int n,d,x,middle=0,zx,zd; cin>>n; for(int i=1;i<=n;i++) cin>>f[i]; d=f[1]; x=f[1]; for(int j=1;j<=n;j++) { if(f[j]>=d) { d=f[j]; zd=j; } } for(int j=1;j<=n;j++) { if(f[j]<=x) { x=f[j]; zx=j; } } middle=f[1]; f[1]=x; f[zx]=middle; middle=f[n]; f[n]=d; f[zd]=middle; for(int g=1;g<=n;g++) cout<<f[g]<<" "; return 0; }

    • 0
      @ 2022-11-5 15:09:15
      #include<bits/stdc++.h> 
      using namespace std; 
      int a[105]; 
      int main(){ 
      int n,min,max,b,c; 
      cin>>n>>a[1]; 
      min = a[1]; 
      max = a[1]; 
      for(int i=2;i<=n;i++) { 
      cin>>a[i]; 
      if(a[i]>max){ 
      max = a[i]; 
      b = i; 
      } 
      if(a[i]<min) {
      min = a[i]; c = i; 
      } 
      } 
      a[c] = a[1]; 
      a[1] = min; 
      a[b] = a[n]; 
      a[n] = max; 
      for(int i=1;i<=n;i++) { 
      cout<<a[i]<<" "; 
      } 
      return 0; 
      }
      
      • 0
        @ 2022-11-5 15:08:57
        #include<bits/stdc++.h> 
        using namespace std; 
        int a[105]; 
        int main(){ 
        int n,min,max,b,c; 
        cin>>n>>a[1]; 
        min = a[1]; 
        max = a[1]; 
        for(int i=2;i<=n;i++) { 
        cin>>a[i]; 
        if(a[i]>max){ 
        max = a[i]; 
        b = i; 
        } 
        if(a[i]<min) {
        min = a[i]; c = i; 
        } 
        } 
        a[c] = a[1]; 
        a[1] = min; 
        a[b] = a[n]; 
        a[n] = max; 
        for(int i=1;i<=n;i++) { 
        cout<<a[i]<<" "; 
        } 
        return 0; 
        }
        
        • 0
          @ 2022-11-5 13:39:21

          #include<bits/stdc++.h> using namespace std; int a[105]; int main(){ int n,min,max,b,c; cin>>n>>a[1]; min = a[1]; max = a[1]; for(int i=2;i<=n;i++){ cin>>a[i]; if(a[i]>max){ max = a[i]; b = i; } if(a[i]<min){ min = a[i]; c = i; } } a[c] = a[1]; a[1] = min; a[b] = a[n]; a[n] = max; for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } return 0; }

          • -1
            @ 2022-11-5 13:18:31
            #include<bits/stdc++.h>
            using namespace std;
            int f[323];
            int main(){
            	int n,d,x,middle=0,zx,zd;
            	cin>>n;
            	for(int i=1;i<=n;i++)
            	    cin>>f[i];
            	d=f[1];
            	x=f[1];
            	for(int j=1;j<=n;j++) {
            		if(f[j]>=d) {
            		   d=f[j];
            		   zd=j;
            		}
            	}
            	for(int j=1;j<=n;j++) {
            		if(f[j]<=x) {
            		   x=f[j];
            		   zx=j;
            		}
            	}
            	middle=f[1];
            	f[1]=x;
            	f[zx]=middle;
            	middle=f[n];
            	f[n]=d;
            	f[zd]=middle;
            	for(int g=1;g<=n;g++)
            		cout<<f[g]<<" ";
            	return 0;
            }
            
            • -1
              @ 2022-11-5 11:07:46

              #include<bits/stdc++.h> using namespace std; int a[105]; int main() { int n,min,max,b,c; cin>>n>>a[1]; min = a[1]; max = a[1]; for(int i=2;i<=n;i++) { cin>>a[i]; if(a[i]>max) { max = a[i]; b = i; } if(a[i]<min) { min = a[i]; c = i; } } a[c] = a[1]; a[1] = min; a[b] = a[n]; a[n] = max; for(int i=1;i<=n;i++) { cout<<a[i]<<" "; } return 0; }

              • -1
                @ 2022-10-30 13:28:14

                #include<bits/stdc++.h> using namespace std; int a[105]; int main(){ int n,min,max,b,c; cin>>n>>a[1]; min = a[1]; max = a[1]; for(int i=2;i<=n;i++){ cin>>a[i]; if(a[i]>max){ max = a[i]; b = i; } if(a[i]<min){ min = a[i]; c = i; } } a[c] = a[1]; a[1] = min; a[b] = a[n]; a[n] = max; for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } return 0; }

                • -3
                  @ 2022-11-5 13:50:47

                  #include<bits/stdc++.h> using namespace std; int a[105]; int main(){ int n,min,max,b,c; cin>>n>>a[1]; min = a[1]; max = a[1]; for(int i=2;i<=n;i++) { cin>>a[i]; if(a[i]>max){ max = a[i]; b = i; } if(a[i]<min) {min = a[i]; c = i; } } a[c] = a[1]; a[1] = min; a[b] = a[n]; a[n] = max; for(int i=1;i<=n;i++) { cout<<a[i]<<" "; } return 0; }

                  • 1

                  信息

                  ID
                  212
                  时间
                  1000ms
                  内存
                  16MiB
                  难度
                  1
                  标签
                  递交数
                  55
                  已通过
                  42
                  上传者