Given an integer N containing the digit four a minimum of as soon as. The job is to divide the quantity into two elements x1 and x2 such that:
x1 + x2 = N.
And not one of the elements comprise the digit four.
Note that there could also be a number of solutions.
Input: N = four
Output: 1 three
1 + three = four
Input: N = 9441
Output: 9331 110
9331 + 110 = 9441
Approach: Since quantity could be too massive take the quantity as string. Divide it into two strings:
For string 1, discover all of the positions of digit four within the string change it to three we will additionally change it to a different quantity.
For the second string put 1 in any respect positions of digit four and put zero in any respect remaining positions from the first place of digit four to the top of the string.
Below is the implementation of the above strategy:
utilizing namespace std;
void twoParts(string str)
int flag = zero;
string a = “”;
for (int i = zero; i < str.size(); i++)
cout << str << " " << a;
string str = “9441”;
If you want GeeksforGeeks and wish to contribute, it’s also possible to write an article utilizing contribute.geeksforgeeks.org or mail your article to email@example.com. See your article showing on the GeeksforGeeks foremost web page and assist different Geeks.
Please Improve this text if you happen to discover something incorrect by clicking on the “Improve Article” button beneath.
Article Tags :
Be the First to upvote.
Please write to us at firstname.lastname@example.org to report any problem with the above content material.
first_page Number of instances the biggest excellent sq. quantity could be subtracted from N
Share this submit!