码迷,mamicode.com
首页 > 其他好文 > 详细

入门模拟A1009 Product of Polynomials(25)

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

标签:c++   pac   col   +=   style   http   ++i   bit   ++   

2019-12-21

14:29:21

技术图片

 

 

#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAX_LEN = 10001;
int main(){
    /*//A多项式,B多项式:
    vector<int,double> A(MAX_LEN);
    //初始化 
    for(int i=0;i<MAX_LEN;++i){
        A[i]=0;
    }
    hash_map<int,double> B(MAX_LEN);
    for(int i=0;i<MAX_lEN;++i){
        B[i]=0;
    }
    //
    int count = 0;
    cin>>count;
    for(int i=0;i<count;++i){
        int fir = 0;
        double sec = 0;
        cin>>fir;
        cin>>sec;
        A[fir] = sec;
    } 
    int count2=0;
    cin>>count2;
    for(int i =0;i<count2;++i){
        int fir = 0;
        double sec = 0;
        cin>>fir;
        cin>>sec;
        B[fir] = sec;
    }
    //
    for(int i=0;i<MAX_LEN;++i){
        if(A[i]!=0){
            B[i] += A[i];
        }
    }
    int count1 = 0;
    for(int i=0;i<MAX_LEN;++i){
        if(B[i]!=0){
            count1++;
        }
    }
    cout<<count1;
    for(int i=MAX_LEN-1;i>=0;--i){
        if(B[i]!=0){
            cout<<i<<B[i]<<" ";
        }
    }*/
    //A,B:
    double A[MAX_LEN]={0};
    double B[MAX_LEN]={0};
    int count = 0;
    cin>>count;
    for(int i=0;i<count;++i){
        int fir = 0;
        double sec = 0;
        cin>>fir;
        cin>>sec;
        A[fir] =  sec;
    }
    int count2=0;
    cin>>count2;
    for(int i =0;i<count2;++i){
        int fir = 0;
        double sec = 0;
        cin>>fir;
        cin>>sec;
        B[fir]  = sec;
    }
    for(int i=0;i<MAX_LEN;++i){
        if(A[i]!=0){
            B[i] += A[i];
        }
    }
    int count1 = 0;
    for(int i=0;i<MAX_LEN;++i){
        if(B[i]!=0){
            count1++;
        }
    }
    cout<<count1;
    for(int i=MAX_LEN-1;i>=0;--i){
        if(B[i]!=0){
            cout<<" "<<i<<" "<<B[i];
        }
    }
    system("pause");
    return 0;
} 

入门模拟A1009 Product of Polynomials(25)

标签:c++   pac   col   +=   style   http   ++i   bit   ++   

原文地址:https://www.cnblogs.com/JasonPeng1/p/12076846.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!