首页 > 其他 > 详细

入门模拟A1009 Product of Polynomials(25)

时间:2019-12-23 15:21:53      阅读:71      评论:0      收藏:0      [点我收藏+]

2019-12-23

14:54:40

技术分享图片

 

 

#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAX_LEN = 2004;
int main(){
    double temp1[MAX_LEN]={0};
    double temp2[MAX_LEN]={0};
    int tem1;
    cin>>tem1;
    for(int i =0;i<tem1;++i){
        int fir;
        double sec;
        cin>>fir;
        cin>>sec;
        temp1[fir] = sec;
    }
    int tem2;
    scanf("%d",&tem2);
    for(int i=0;i<tem2;++i){
        int fir = 0;
        double sec = 0;
        cin>>fir;
        cin>>sec;
        temp2[fir] = sec;
    }
    double temp3[MAX_LEN] = {0};
    int count = 0;
    for(int i =MAX_LEN;i>=0;--i){
        for(int j=MAX_LEN;j>=0;--j){
            if(temp1[i]==0){
                break;
            }
            else{
                if(temp2[j]!=0){
                    //count++;
                    temp3[j+i] += (temp1[i]*temp2[j]);
                }
            } 
        }
    }
    for(int i=MAX_LEN;i>=0;--i){
        if(temp3[i]!=0&&i!=MAX_LEN){
            count++;
        }
    }
    cout<<count;
    for(int i=MAX_LEN;i>=0;--i){
        if(temp3[i]!=0&&i!=MAX_LEN){
            printf(" %d %.1f",i,temp3[i]);
        }
    }

入门模拟A1009 Product of Polynomials(25)

原文:https://www.cnblogs.com/JasonPeng1/p/12083770.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!