编辑代码

#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main() {
    int a[100];
    int n,max,min,max2,min2,count=0;
    char m;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m;
        a[i] = (int)m;
        if(i==0){
            max = a[i];
            min = a[i];
        }else{
            if(a[i]>max){
                max = a[i];
            }
            if(a[i]<min){
                min = a[i];
            }
        }
    }

    for(int i=0;i<n;i++){
        if(a[i]!=max&& a[i]!=min){
            if(count==0){
                max2 = a[i];
                min2 = a[i];
            }else{
                if(a[i]>max2){
                    max2 = a[i];
                }
                if(a[i]<min2){
                    min2 = a[i];
                }
            }
            count++;
        }
    }
    cout << (char)max2 <<" "<< (char)min2;
    
    
	return 0;
}