'commit'
This commit is contained in:
33
TangDou/LianXiTi50/35.cpp
Normal file
33
TangDou/LianXiTi50/35.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user