﻿/*
6. Cseréljük fel egymással egy szám legkisebb
   és legnagyobb számjegyét!
   https://www.pbinfo.ro/probleme/4317/cifre19
*/
#include <iostream>
using namespace std;

int main()
{
    int n;
    cout << "n = ";
    cin >> n;

    int p = 1;
    while (n / p > 0)
        p *= 10;
    p /= 10;

    int maximum = -1, minimum = 10;
    int max_hely, min_hely;

    while (p > 0) {
        int szj = (n/p) % 10;

        if (szj > maximum) {
            maximum = szj;
            max_hely = p;
        }
        if (szj < minimum) {
            minimum = szj;
            min_hely = p;
        }

        p = p / 10;
    }

    // cseréljük a maximumot
    n = n/(10*max_hely)*(10*max_hely)
        + (minimum * max_hely)
        + (n % max_hely);


    // cseréljük a minimumot
    n = n/(10*min_hely)*(10*min_hely)
        + (maximum * min_hely)
        + (n % min_hely);

    cout << n << endl;

    return 0;
}
