1009 Product of Polynomials (25 分)
这题目要卡的话只能卡第一个吧,考虑零项之后,这道题就简单了。
#include<iostream>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{double cun1[10001]={0},cun[10001]={0};set<int>chu1,chu;int n,exponents;//指数double coefficients;//系数cin>>n;while (n--){cin>>exponents>>coefficients;cun1[exponents] += coefficients;chu1.insert(exponents);}cin>>n;while (n--){cin>>exponents>>coefficients;for (set<int>::iterator it = chu1.begin();it!=chu1.end();it++){int x = exponents+(*it);double y = coefficients*(cun1[*it]);cun[x]+=y;chu.insert(x);}}vector<int>jiujicunchu;//因为我不会set倒序输出,所以我就先转换成vector;究极存储//有没有人会的教教孩子吧。for (set<int>::iterator it = chu.begin();it!=chu.end();it++){if (cun[*it]!=0) jiujicunchu.push_back(*it);//防止零项存储进来,第一个测试点}int cou = jiujicunchu.size();cout<<cou;for (int i=jiujicunchu.size()-1;i>=0;i--){if (cun[jiujicunchu[i]]!=0){cout<<" "<<jiujicunchu[i];cout<<" "<<fixed<<setprecision(1)<<cun[jiujicunchu[i]];}}return 0;
}