Professional Documents
Culture Documents
Ass Mod
Ass Mod
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct term {
double coeff;
int degree;
};
int addLast; // Last element of addition i.e. whatever the last index of addition
is +1
void add (int x, int y ){
bool common;
for (int i=0;i<x;i++){
common = false;
for (int j=x; j<x+y; j++){
if (ARR[i].degree == ARR[j].degree){
ARR[last].degree = ARR[i].degree;
ARR[last].coeff = ARR[i].coeff + ARR[j].coeff;
common = true;
last ++;
}
}
if (common == false){
ARR[last] = ARR[i];
last ++;
}
}
for (int i=x;i<x+y;i++){
common = false;
for (int j=0; j<x; j++){
if (ARR[i].degree == ARR[j].degree){
common = true;
}
}
if (common == false){
ARR[last] = ARR[i];
last ++;
}
}
addLast = last;
}
int multLast;
void multiply (int x, int y){
for (int i=addLast;i<250;i++){
ARR[i].coeff=0;
ARR[i].degree=0;
}
for (int i=0;i<x;i++){
for(int j=x;j<x+y;j++){
ARR[last].coeff+=ARR[i].coeff*ARR[j].coeff;
ARR[last].degree=ARR[i].degree+ARR[j].degree;
last++;
}
}
multLast=last;
}
int main(){
int x; int y;
cin >> x ;
takeInput (x, 0);
cin >> y ;
takeInput (y,x);
add (x,y);
multiply (x,y);
// Output Code