1002|1002 A+B for Polynomials (25)(25 分)
【1002|1002 A+B for Polynomials (25)(25 分)】建立数组,数组下标作为指数
#include
using namespace std;
const int maxn = 1e3 + 10;
double a[maxn], b[maxn];
int k;
void read(double a[])
{
scanf("%d", &k);
for (int i = 0;
i < k;
i++)
{
int exp;
double coef;
scanf("%d%lf", &exp, &coef);
a[exp] = coef;
}
}
int main()
{
read(a);
read(b);
int cnt = 0;
for (int i = 0;
i < maxn;
i++)
{
a[i] += b[i];
if (a[i])cnt++;
}
printf("%d", cnt);
for (int i = maxn;
i >= 0;
i--)
{
if (a[i])printf(" %d %.1f", i, a[i]);
}
return 0;
}
推荐阅读
- whlie循环和for循环的应用
- ffmpeg源码分析01(结构体)
- 【WORKFOR】最真的自己
- R|R for data Science(六)(readr 进行数据导入)
- performSelectorOnMainThread:withObject:waitUntilDone:参数设置为NO或YES的区别
- JavaScript|JavaScript — 初识数组、数组字面量和方法、forEach、数组的遍历
- Swift7|Swift7 - 循环、函数
- 65|65 - Tips for File Handling
- 40
- 360|360 将停止 StartCom 数字证书业务;微软的 Visual Studio Tools for AI 现已提供使用