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