浙大PAT (Advanced Level) Practise 1009 Product of Polynomials (25)
2013-06-15 22:36
459 查看
/*本题与1002类似,只是将简单的两个数组相加,改为两个数组相乘,采用双循环可解,代码如下*/ #include <iostream> using namespace std; int main() { int K; while(cin>>K) { double a[1001]={0},b[1001]={0},c[2001]={0}; //a[],b[]数组储存两个系数数组,c[]储存结果 int n; for(int i=0;i<K;++i) { cin>>n; cin>>a ; } cin>>K; for(int i=0;i<K;++i) { cin>>n; cin>>b ; } for(int i=0;i<1001;++i) //双循环获得多项式相乘结果 { for(int j=0;j<1001;++j) { c[i+j]+=a[i]*b[j]; } } int count=0; for(int i=0;i<2001;++i) //求多项式中的非零项数目 if(c[i]) ++count; cout<<count; for(int i=2000;i>=0;--i) if(c[i]) printf(" %d %.1lf",i,c[i]); cout<<endl; } return 0; }
相关文章推荐
- PAT (Advanced Level) Practise 1009 Product of Polynomials (25)
- 浙大PAT (Advanced Level) Practise 1002. A+B for Polynomials (25)
- 浙大PAT (Advanced Level) Practise 1003. Emergency (25)
- PAT (Advanced Level) Practise 1002 A+B for Polynomials (25)
- PAT (Advanced Level) Practise 1009 Product of Polynomials
- PAT (Advanced Level) Practise 1002. A+B for Polynomials (25)
- PAT (Advanced Level) Practise 1002. A+B for Polynomials (25)
- 1009. Product of Polynomials (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1009. Product of Polynomials (25)
- PAT (Advanced Level) Practise - 1009. Product of Polynomials (25)
- 1009. Product of Polynomials (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1002 A+B for Polynomials (25)
- PAT (Advanced Level) Practise 1009. Product of Polynomials (25)
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT(Advanced Level) 1009 - Product of Polynomials(水题)
- 浙大PAT (Advanced Level) Practise 1043 Is It a Binary Search Tree (25)
- 浙大PAT (Advanced Level) Practise 1020 Tree Traversals (25)
- Pat(Advanced Level)Practice--1009(Product of Polynomials)
- PAT (Advanced Level) Practise - 1002. A+B for Polynomials (25)
- PAT (Advanced Level) Practise 1044 Shopping in Mars (25)