多项式相乘

在这里插入图片描述

注意:
1,先按次幂排序,then合并同次幂
2,赋值;a[]-->b[]-->c[]
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct st{
    int x;
    int y;
}a[5],b[5],c[5];
bool comp(st a,st b){
    return a.y > b.y;
}
int main(){
    for(int i = 1; i <= 4; i++){
        cin >> a[i].x >> a[i].y;
    }
    b[1].x = a[1].x * a[3].x;
    b[1].y = a[1].y + a[3].y;
    b[2].x = a[1].x * a[4].x;
    b[2].y = a[1].y + a[4].y;
    b[3].x = a[2].x * a[3].x;
    b[3].y = a[2].y + a[3].y;
    b[4].x = a[2].x * a[4].x;
    b[4].y = a[2].y + a[4].y;
    sort(b+1,b+5,comp);
    b[5].x = b[5].y = 0;
    int p = 0;
    for(int i = 1; i <= 4; i++){
        if(b[i].y == b[i+1].y){
            c[p].x = b[i].x + b[i+1].x;
            c[p++].y = b[i].y;
            i++;
        }else {
            c[p++] = b[i];
        }
    }
    for(int i = 0; i < p; i++){
        cout << c[i].x << " " << c[i].y <<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值