#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { int n; cin >> n; int str[100],out[100]; int max, min; for (int i=0; i < n; i++) { cin >> str[i]; out[i] = str[i]; }; min = 0; max = 0; for (int i=0; i < n; i++) { if (str[i] < str[min]) { min = i; } } for (int i=0; i < n; i++) { if (str[i] > str[max]) { max=i; } } //out[0] = str[min]; //out[n-1] = str[max]; //out[min]=str[0]; //out[max]=str[n-1]; int temp; temp = out[min]; out[min] = out[0]; out[0] = temp; temp = out[max]; out[max] = out[n - 1]; out[n - 1] = temp; cout << out[0]; for (int i = 1; i < n; i++) { cout <<" "<< out[i]; } return 0; } |
Double click to view unformatted code.