PAT 甲级 1002
题目描述:多项式求和问题
输入两个多项式,输出和的多项式(多项式按指数递减排列)
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 2 1.5 1 2.9 0 3.2
解题思路:
由于多项式已经按指数递减排列,构造两个数组,存放输入多项式,然后对两个数组进行依次比较,放入第三个数组中。(与数据结构线性表一节中,合并两个递减表的操作一致)
#include<stdio.h>
#include<iostream>
#include<iomanip>
using namespace std;
typedef struct {
int expn; //指数
float coef; //系数
}Node;
int main() {
Node a[11], b[11], c[22];
int i, j, k=0