forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolymul1.cpp
54 lines (46 loc) · 1.13 KB
/
polymul1.cpp
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
#include <iostream>
#include <vector>
using namespace std;
int main() {
// Make input faster
ios::sync_with_stdio(false);
cin.tie(NULL);
int cases;
cin >> cases;
for(int i = 0; i < cases; i++) {
vector<int> v1;
vector<int> v2;
vector<int> v3;
// Take in the first polynomial
int size1;
cin >> size1;
size1++;
for(int j = 0; j < size1; j++) {
int temp;
cin >> temp;
v1.push_back(temp);
}
// Take in the second polynomial
int size2;
cin >> size2;
size2++;
for(int j = 0; j < size2; j++) {
int temp;
cin >> temp;
v2.push_back(temp);
}
// Create the third polynomial
int size3 = size1 + size2 - 2;
v3.resize(size3+1, 0);
for(int j = 0; j < v1.size(); j++) {
for(int k = 0; k < v2.size(); k++) {
v3[j+k] += v1[j] * v2[k];
}
}
cout << size3 << '\n';
for(auto i : v3) {
cout << i << " ";
}
cout << '\n';
}
}