some programs!
This commit is contained in:
1 parent
5d30e847c1
commit
ed054247d5
32 files changed
+1882
-149
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Polynomial : public map<unsigned int, long long, greater<>> {
|
||||
public:
|
||||
Polynomial operator+=(const Polynomial& other) {
|
||||
for (const auto& [exp, coef] : other) {
|
||||
(*this)[exp] += coef;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void print() const {
|
||||
for (const auto& [exp, coef] : *this) {
|
||||
if (coef == 0) { continue; }
|
||||
cout << "[ " << coef << " " << exp << " ] ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
};
|
||||
|
||||
Polynomial input_polynomial() {
|
||||
long long coefficient;
|
||||
int exponent;
|
||||
Polynomial polynomial;
|
||||
while (cin >> coefficient >> exponent && exponent >= 0) {
|
||||
polynomial[exponent] += coefficient;
|
||||
}
|
||||
return polynomial;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int _ = 0; _ < n; _++) {
|
||||
Polynomial polynomial1 = input_polynomial();
|
||||
Polynomial polynomial2 = input_polynomial();
|
||||
polynomial1 += polynomial2;
|
||||
polynomial1.print();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user