Reframe with Hundredth Digit

The program must accept an integer N and a sum value X (sum of unit digit, tenth digit and hundredth digit of N) as the input. The hundredth digit is removed from N. The program must find the hundredth digit and print N by reframing it as the output.

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

Input Format:
The first line contains the two integer values N and X separated by a space.

Output Format:
The first line contains the reframed N.

Example Input/Output 1:
Input:
1269 20

Output:
12569

Explanation:
The sum of the last two digits in 1269 is 15. The difference between 20 and 15 is 5 (20-15).
So the hundredth digit is 5. After reframing the N is 12569.
Hence the output is 12569.

Example Input/Output 2:
Input:
43217 9

Output:
432117

n, x = map(int, input().split())

# Extracting unit and tenth digit
unit_digit = n % 10
tenth_digit = (n // 10) % 10

# Calculating the hundredth digit
hundredth_digit = x - (unit_digit + tenth_digit)

# Reframing the number
reframed_number = (n // 100) * 1000 + hundredth_digit * 100 + tenth_digit * 10 + unit_digit

print(reframed_number)
#include<stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    int ud=a%10;
    int td=(a/10)%10;


    int dig=b-(ud+td),sum=0;

    int x=a/100;

    int num=x*1000+dig*100+td*10+ud;

    printf("%d",num);
}
#include <iostream>
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;

    // Extracting unit and tenth digit
    int unit_digit = n % 10;
    int tenth_digit = (n / 10) % 10;

    // Calculating the hundredth digit
    int hundredth_digit = x - (unit_digit + tenth_digit);

    // Reframing the number
    int reframed_number = (n / 100) * 1000 + hundredth_digit * 100 + tenth_digit * 10 + unit_digit;

    cout << reframed_number;
    return 0;
}
import java.util.Scanner;

public class ReframeNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();

        // Extracting unit and tenth digit
        int unit_digit = n % 10;
        int tenth_digit = (n / 10) % 10;

        // Calculating the hundredth digit
        int hundredth_digit = x - (unit_digit + tenth_digit);

        // Reframing the number
        int reframed_number = (n / 100) * 1000 + hundredth_digit * 100 + tenth_digit * 10 + unit_digit;

        System.out.println(reframed_number);
    }
}
Previous Article

Combine Two Numbers by Alternating Digits

Next Article

Adding a Digit to Maintain Ascending Order

Write a Comment

Leave a Comment

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