-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongMultiplication.cpp
More file actions
56 lines (50 loc) · 1.19 KB
/
LongMultiplication.cpp
File metadata and controls
56 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool arrtoint(int index, vector<int> &num1, vector<int> &num2){
string a,b;
for(int i = 0; i <= index; i++){
a.push_back(num1[i] + '0');
b.push_back(num2[i] + '0');
}
return a > b;
}
int main(){
int t;
cin >> t;
while(t--){
string n_str, m_str;
cin >> n_str >> m_str;
vector<int> num1, num2;
for (char c : n_str) {
num1.push_back(c - '0');
}
for (char c : m_str) {
num2.push_back(c - '0');
}
int size = min(num1.size(),num2.size());
// logic
for(int i = 1; i < size; i++){
int mini = min(num1[i],num2[i]);
int maxi = max(num1[i],num2[i]);
if(arrtoint(i-1, num1, num2)){
num1[i] = mini;
num2[i] = maxi;
}
else{
num1[i] = maxi;
num2[i] = mini;
}
}
for(auto i : num1){
cout << i;
}
cout << endl;
for(auto i : num2){
cout << i;
}
cout << endl;
}
return 0;
}