首页 > 学院 > 开发设计 > 正文

PAT甲级1009

2019-11-06 06:02:49
字体:
来源:转载
供稿:网友
#include <iostream>#include <iomanip>#include <vector>using namespace std;/* run this PRogram using the console pauser or add your own getch, system("pause") or input loop */struct Polynomials{ int exponent; float coefficient; };int main(int argc, char** argv) { int K1,K2; float Poly3[2001]; Polynomials Poly1[10],Poly2[10]; for(int i=0;i<2001;i++){ Poly3[i]=0; } cin>>K1; for(int i=0;i<K1;i++){ cin>>Poly1[i].exponent>>Poly1[i].coefficient; } cin>>K2; for(int i=0;i<K2;i++){ cin>>Poly2[i].exponent>>Poly2[i].coefficient; } float Poly3Coefficient=0; int Poly3Exponent=0; for(int i=0;i<K1;i++){ for(int j=0;j<K2;j++){ Poly3Coefficient= Poly1[i].coefficient*Poly2[j].coefficient; Poly3Exponent=Poly1[i].exponent+Poly2[j].exponent; Poly3[Poly3Exponent]=Poly3[Poly3Exponent]+Poly3Coefficient; } } int count=0; vector<Polynomials> result; Polynomials item; for(int i=2000;i>=0;i--){ if(Poly3[i]!=0){ item.coefficient=Poly3[i]; item.exponent=i; result.push_back(item); count++; } } cout<<count; for(int i=0;i<count;i++){ cout<<" "<<setfill('0') <<setiosflags(ios::fixed)<<setprecision(1)<<result[i].exponent<<" "<<result[i].coefficient; } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表