【PAT甲级】1009 Product of Polynomials

it2024-08-18  40

题目链接:1009 Product of Polynomials

#include <iostream> #include <map> using namespace std; int main(){ int K, a; double b; map<int,double> mp1, mp2; cin >> K; for(int i = 0; i < K; i++){ scanf("%d %lf", &a, &b); mp1[a] = b; } cin >> K; for(int i = 0; i < K; i++){ scanf("%d %lf", &a, &b); for(auto it: mp1){ mp2[a+it.first] += b * it.second; if(!mp2[a+it.first]) mp2.erase(a+it.first);//删除系数为0的项 } } auto it = mp2.end(); cout << mp2.size(); while(it!=mp2.begin()){//倒序输出 it--; printf(" %d %.1f",it->first,it->second); } }

 

最新回复(0)