1002. A+B for Polynomials (25)

#include "stdafx.h"
#include <iostream>
#include <map>

using namespace std;

int main()
{
	int n1;
	scanf("%d", &n1);

	map<int, double> id;
	int i, a;
	double b;

	for(i = 1; i <= n1; i++)
	{
		scanf("%d%lf", &a, &b);
		id[a] = b;
	}

	int n2;
	scanf("%d", &n2);

	for(i = 1; i <= n2; i++)
	{
		scanf("%d%lf", &a, &b);
		id[a] += b;
	}

	int count = 0;
	double second;
	map<int, double> ::reverse_iterator it;

	for(it = id.rbegin(); it != id.rend(); it++)
	{
		second = it->second;
		if(second != 0)
		{
			count++;
		}
	}

	printf("%d", count);

	int first;
	for(it = id.rbegin(); it != id.rend(); it++)
	{
		first = it->first;
		second = it->second;

		if(second != 0)
		{
			printf(" %d %.1lf", first, second);
		}
	}

	printf("\n");

	system("pause");
	return 0;
}

 

posted on 2025-11-23 16:49  王景迁  阅读(0)  评论(0)    收藏  举报

导航