#include <iostream>
#include <vector>
class Multi{
public:
Multi(std::vector<double>&& vec): dim(vec.size()){
data=new double[dim];
for(int i=0; i<dim; ++i){
data[i]=vec[i];
}
}
Multi(std::vector<double>& vec): dim(vec.size()){
data=new double[dim];
for(int i=0; i<dim; ++i){
data[i]=vec[i];
}
}
~Multi(){
delete[] data;
}
Multi operator+(Multi& other){
if(dim>=other.dim){
std::vector<double> tmp(dim);
for(int i=0; i<other.dim; ++i){
tmp[i]=data[i]+other.data[i];
}
for(int i=other.dim; i<dim; ++i){
tmp[i]=data[i];
}
Multi mul(tmp);
return mul;
}else{
std::vector<double> tmp(other.dim);
for(int i=0; i<dim; ++i){
tmp[i]=data[i]+other.data[i];
}
for(int i=dim; i<other.dim; ++i){
tmp[i]=other.data[i];
}
Multi mul(tmp);
return mul;
}
}
void print_format(void){
std::cout<<"MULTI:"<<'\n';
for(int i=0; i<dim; i++){
std::cout<<data[i]<<"x^"<<i;
if(i!=dim-1) std::cout<<'+';
}
std::cout<<'\n';
}
private:
int dim;
double* data;
};
int main(void){
Multi mul1(std::vector<double>{1.0, 2.0, 3.0});
Multi mul2(std::vector<double>{2.0, 3.0, 4.0, 5.0});
Multi mul3=mul1+mul2;
mul3.print_format();
return 0;
}