Help

How do I write the following program? If we have the variable a and b (condition that the variables can have up to 1000 digits), and we can enter the variable a (example a = 323) and the variable b (example b = 4546).How do I combine variable a and variable b and get variable x (x = 3234546)?And how do I decompose that same variable x into a and b (example x = 3234546, I decompose that variable into variable a = 323 and b = 4546)?
Use std::string
Combining them is just converting to string rep and concatenating them and converting back.

For the decompose, you need to know the break point as 3234546 could be 323 & 4546 or 32 & 34546 etc etc
Can anyone write a code for me ?
There is subforum "Jobs". Perhaps someone there ...
1
2
3
4
5
6
7
string a;
cin >> a;
string b;
cin >> b;
string x = a + b;
cout << x << '\n';
cout << x.substr(0, 3) << ' ' << x.substr(3);

That'll be $19.95 (plus tip).
Last edited on
That was really close Ganado.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;

int main()
{
 string a;
cin >> a;
string b;
cin >> b;
string x = a + b;
cout << x << '\n';
cout << x.substr(0, a.length()) << ' ' << x.substr(a.length());

}
Last edited on
Topic archived. No new replies allowed.