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
数组保存。
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<iostream>
using namespace std;
#include<stdio.h>
#include<memory.h>
double exp[1001];
int main()
{
int e;
double c;
int N;
int count=0;
memset(exp,0,sizeof(exp));
for(int i=0;i<2;i++)
{
cin>>N;
while(N--)
{
cin>>e;
cin>>c;
if(exp[e]==0)
count++;
exp[e]+=c;
if(exp[e]==0)
count--;
}
}
cout<<count;
for(int i=1000;i>=0;i--)
{
if(exp[i]!=0)
printf(" %d %.1f",i,exp[i]);
}
}
本文详细介绍了多项式加法的实现过程,包括输入解析、内存初始化、加法运算及结果输出,通过C++代码实例展示了算法的具体实现。

324

被折叠的 条评论
为什么被折叠?



