Enclose Number Between its Maximum and Minimum Digits

In the realm of digital data analytics and number theory, understanding the range and distribution of digits within a number is crucial. This concept finds its roots in various applications, from statistical data visualization to computational algorithms in modern banking systems.

Your programming challenge, inspired by real-world digital data processing scenarios, is to craft an algorithm that can dynamically represent the range of digits within an integer. This method is not just an academic exercise but resonates with practical scenarios like enhancing encryption techniques, optimizing storage in database systems, or even in rapid data analysis platforms dealing with vast streams of numbers.

For this computational task, you’ll accept an integer, N, as your input. Dive into its digits and enclose this number between its smallest and largest digits. This operation transforms the original number, giving a visual cue about its digit span, beneficial for real-time data analytics and digital encryption processes.

Boundary Condition(s):
10 <= N <= 10^8

Input Format:
The first line comprises the integer, N, awaiting its transformation.

Output Format:
The output reveals the transformed number, shedding light on its digit range with added context.

Example Input/Output 1:
Input:
4352

Output:
243522

Explanation:
From the analytical viewpoint, the minimum digit in 4352 is 2, and the maximum zooms to 5. Naturally, enclosing 4352 between these digits results in 243522, a number more informative for computational systems to decipher its digit spectrum.

Example Input/Output 2:
Input:
21978

Output:
9219789

Explanation:
Digital algorithms can quickly discern that the smallest digit in 21978 is 1 and the pinnacle is 9. A calculated enclosure of 21978 between these figures crafts 9219789, a number enriched with contextual information about its original.

#include <iostream>
#include <string>
using namespace std;

int main() {
    string N;
    cin >> N;

    char max_digit = '0';
    char min_digit = '9';
    for(char c : N) {
        if(c > max_digit) max_digit = c;
        if(c < min_digit) min_digit = c;
    }

    cout << min_digit << N << max_digit;
    return 0;
}
import java.util.Scanner;

public class EncloseDigits {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();

        char max_digit = '0';
        char min_digit = '9';
        for(char c : N.toCharArray()) {
            if(c > max_digit) max_digit = c;
            if(c < min_digit) min_digit = c;
        }

        System.out.println(min_digit + N + max_digit);
    }
}
N = input().strip()
max_digit = max(N)
min_digit = min(N)
print(min_digit + N + max_digit)
#include<stdio.h>
#include<string.h>

int main() {
    char N[10];
    scanf("%s", N);

    char max_digit = '0';
    char min_digit = '9';
    for(int i = 0; N[i]; i++) {
        if(N[i] > max_digit) max_digit = N[i];
        if(N[i] < min_digit) min_digit = N[i];
    }

    printf("%c%s%c", min_digit, N, max_digit);
    return 0;
}
Previous Article

Difference Between Square of Largest and Smallest Digit

Next Article

Function reverse - CTS PATTERN

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *