多项式加法
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>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
int count = 0;
vector<double> V(1001,0);
int N;
for (int i = 0; i < 2; i++)
{
cin>>N;
for (int i = 0; i < N; i++)
{
int x;
double y;
cin>>x>>y;
if (y != 0 && V[x] == 0)
{
count++;
}
V[x] += y;
if (y != 0 && V[x] == 0)
{
count--;
}
}
}
cout<<count;
cout.setf(ios::fixed);
for (int i = 1000; i >=0 ; i--)
{
if (V[i] != 0)
{
cout<<" ";
cout<<i<<" ";
cout<<fixed<<setprecision(1)<<V[i];
}
}
return 0;
}