PAT-甲级1002

传送门

#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
struct Polynomials{
	int exponents;
	double coefficients;
	Polynomials(int exponents,double coefficients){
		this->exponents=exponents;this->coefficients=coefficients;
	}
};
const int MAX=1001;
double array[MAX];
int main(int argc,char **argv){
	int N,K;double C;
	memset(array,0,sizeof(array));
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>K>>C;
		array[K]=C;
	}
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>K>>C;
		array[K]+=C;
	}
	vector<Polynomials> src;
	for(int i=0;i<MAX;i++)
		if(array[i]!=0){
			Polynomials temp(i,array[i]);
			src.push_back(temp);
		}

	cout<<src.size();
	for(auto it=src.rbegin();it!=src.rend();it++)
		printf(" %d %.1f",(*it).exponents,(*it).coefficients);
	cout<<endl;
	return 0;
}


你可能感兴趣的:(PAT-甲级1002)