Question: Task 2 In this task you are given two strings of digits that represent ( possibly very large ) integers. Your goal is to make
Task
In this task you are given two strings of digits that represent possibly very large integers. Your goal is to make those numbers as close to one another as possible. In other words, you want to minimize the absolute value of their difference. You can swap some of the corresponding digits eg the first digit of the first number with the first digit of the second number, the second digit of the first number with the second digit of the second number, etc. Swapping the digits is an extremely tiring task, so you want to make as few swaps as possible.
Write a function:
int solutionstring &S string &T;
that, given two strings and both of length returns the minimum number of swaps needed to minimize the difference between the two numbers represented by the input strings.
For example, given and your function should return
We can swap the second and the fourth digits and obtain and The difference between the numbers is and the number of swaps is One can easily check that the difference is the smallest possible. Note that we could obtain the same difference by swapping the first, third and fifth digits, but this solution requires three swaps.
Write an efficient algorithm for the following assumptions:
lengths of and T are equal and within the range ;
S and T consist only of digits and no other characters;
SOLVE IT IN CPP SIMPLE TERMS
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
