#include <iostream> using namespace std; int main() { int n; cin >> n; int heights[100]; int maxHeight = -1, minHeight = 1000000; int maxIndex = 0, minIndex = 0; for (int i = 0; i < n; i++) { cin >> heights[i]; if (heights[i] > maxHeight) { maxHeight = heights[i]; maxIndex = i; } if (heights[i] < minHeight) { minHeight = heights[i]; minIndex = i; } } int temp = heights[maxIndex]; heights[maxIndex] = heights[minIndex]; heights[minIndex] = temp; for (int i = 0; i < n; i++) { if (i > 0) { cout << " "; } cout << heights[i]; } cout << endl; return 0; } /************************************************************** Problem: 1232 User: panyuchen Language: C++ Result: Accepted Time:6 ms Memory:2072 kb ****************************************************************/