You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
639 B
33 lines
639 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 110;
|
|
const int INF = 0x3f3f3f3f;
|
|
int a[N];
|
|
|
|
/**
|
|
用例: 23 54 34 12 76
|
|
结果: 76 54 34 23 12
|
|
*/
|
|
int main() {
|
|
int n = 5;
|
|
int Max = -INF, Min = INF;
|
|
int Max_pos, Min_pos;
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
cin >> a[i];
|
|
if (a[i] > Max) {
|
|
Max = a[i];
|
|
Max_pos = i;
|
|
}
|
|
if (a[i] < Min) {
|
|
Min = a[i];
|
|
Min_pos = i;
|
|
}
|
|
}
|
|
swap(a[1], a[Max_pos]);
|
|
swap(a[n], a[Min_pos]);
|
|
|
|
for (int i = 1; i <= n; i++) cout << a[i] << " ";
|
|
return 0;
|
|
} |