多项式加法
in Solutions with 34 comments

多项式加法

in Solutions with 34 comments

简单多项式加法代码

#include <bits/stdc++.h>

struct dudeNode{
    int32_t Coefficient;
    int32_t Exponent;
    dudeNode* next;
    dudeNode(int32_t c=0,int32_t e=0):Coefficient(c),Exponent(e){}
};


dudeNode* build(std::vector<int32_t> coeffs,std::vector<int32_t> exp){
    dudeNode* dummy=new dudeNode();
    dudeNode* cur=dummy;
    for(int i=0;i<coeffs.size();++i){
        cur->next=new dudeNode(coeffs[i],exp[i]);
        cur=cur->next;    
    }
    return dummy;
}

void display(dudeNode* dude){
    while(dude->next!=nullptr){
        std::cout<<dude->next->Coefficient<<"x"<<dude->next->Exponent<<"  ";
        dude=dude->next;
    }
    std::cout<<std::endl;
}


dudeNode* Add(dudeNode* a,dudeNode* b){
    dudeNode* result=(dudeNode*)malloc(sizeof(dudeNode));
    dudeNode* curResult=result;
    dudeNode* curA=a;
    dudeNode* curB=b;
    curA=curA->next;
    curB=curB->next;
    while(curA!=nullptr&&curB!=nullptr){
        if(curA->Exponent>curB->Exponent){
            curResult->next=curA;
            curResult=curResult->next;
            curA=curA->next;
        }else if(curA->Exponent<curB->Exponent){
            curResult->next=curB;
            curResult=curResult->next;
            curB=curB->next;
        }else{
            dudeNode* newNode=(dudeNode*)malloc(sizeof(dudeNode));
            newNode->Coefficient=curA->Coefficient+curB->Coefficient;
            if(newNode->Coefficient==0){
                curA=curA->next;
                curB=curB->next;
                continue;
            }
            newNode->Exponent=curA->Exponent;
            curA=curA->next;
            curB=curB->next;
            curResult->next=newNode;
            curResult=curResult->next;
        }
    }
    if(curA!=nullptr){
        curResult->next=curA;
    }
    if(curB!=nullptr){
        curResult->next=curB;
    }
    return result;
}

int main()
{
    dudeNode* a=build({4,3,2,1},{8,7,6,5});
    dudeNode* b=build({},{});
    dudeNode* result=Add(a,b);
    display(result);

}
Responses
  1. Kamagra En France En Ligne Ototoxicity In Adults Due To Amoxicillin Recherche Cialis Forum tadalafil cialis from india Cephalexin Antibiotic Used For

    Reply
  2. lisinopril tablets

    Reply
  3. avodart 1mg lisinopril canada accutane 40 mg

    Reply
  4. Tanning Amoxicillin http://cialibuy.com - Buy Cialis How Long Does Amoxicillin Stay Good Cialis Levitra Femenina

    Reply
  5. metformin 80 mg buy doxycycline mexico prednisone generic cost of furosemide 40 mg lisinopril 10 mg purchase generic levitra order tadalafil albendazole tablets 400 mg price diflucan 100 mg tablet diflucan online cheap sildenafil 20 can i buy ventolin online valtrex cream cost buy arimidex amoxicillin 500mg no prescription furosemide pill buy sildenafil 100mg uk buy lisinopril where to buy clomid pills where to buy avodart

    Reply
  6. zoloft 200 mg pill

    Reply
  7. furosemide otc

    Reply
  8. Propecia Dolore http://cialibuy.com - cheapest cialis 20mg Viagara Generic Buy Cialis Levitra Rezeptfrei In Holland

    Reply
  9. Amoxicillin 500 Mg Used For http://cialibuy.com - Cialis Buy Levitra cialis 5mg Kamagra Tablets Online

    Reply
  10. prednisone canadian pharmacy albendazole 200 mg price buy generic avodart accutane canada 40mg amoxicillin 500 mg where to buy

    Reply
  11. lisinopril 20 mg tablet

    Reply
  12. buy doxycycline arimidex brand name furosemide 50 mg tablets doxycycline 100mg price generic levitra for sale

    Reply
  13. furosemide 40 mg tablet diflucan 150 mg sildenafil 20 mg buy ventolin no prescription

    Reply
  14. zoloft 25 mg sildenafil 40 mg metformin 500 mg diflucan 150 mg furosemide 60 mg

    Reply
  15. diflucan 150 mg 20mg zoloft order furosemide

    Reply
  16. furosemide 20 mg diflucan prescription diflucan 150 albendazole tablet zoloft online 0.5 albuterol sildenafil 20 mg tablet clomid pills doxycycline prescription uk lisinopril 5 mg tablet

    Reply
  17. buy prednisolone 25mg tablets synthroid generic price vibramycin 100 mg metformin 500 mg buy lisinopril online

    Reply
  18. where can i buy cafergot tablets buy synthroid over the counter zithromax z-pak buy motilium online uk

    Reply
  19. tetracycline no prescription

    Reply
  20. can i buy ventolin over the counter in usa

    Reply
  21. Viagra Online Free http://viacialisns.com/# - Buy Cialis Cialis Stripes Erfahrungen online pharmacy Uk Propecia Without Prescription

    Reply
  22. tetracycline 500mg price in india

    Reply
  23. propecia cheapest no prescription cafergot tablets in india can you buy clomid can you buy colchicine over the counter in canada where to get doxycycline motilium over the counter uk generic ventolin price metformin 1000 mg price lisinopril 10 mg price in india lexapro 10 mg

    Reply
  24. ventolin generic sildenafil pills uk lisinopril 10 mg daily lisinopril 12.5 mg 20 mg motilium 10mg tablets discount generic propecia cafergot 100mg

    Reply
  25. prednisolone 5 mg tablet buy motilium generic albuterol without a prescription allopurinol 300 mg tablet retin a from mexico stromectol lisinopril 30 mg daily allopurinol over the counter uk colchicine pill lisinopril 4 mg buy generic metformin price of metformin buy cafergot fluoxetine 40 mg price in india tetracycline 500mg prednisone 20 buy propecia singapore azithromycin 250 mg over the counter zithromax online pharmacy ventolin uk price

    Reply
  26. Generic Levitra Online Canada http://abcialisnews.com - generic 5mg cialis best price Cheap Online Cails Pills Cialis Propecia En Ligne France

    Reply
  27. can i buy doxycycline over the counter uk

    Reply
  28. levitra 20mg best price ventolin generic buy allopurinol tablets tetracycline cost usa prednisone prednisolone

    Reply
  29. synthroid 300 mcg tablets albuterol online canada retin a 0.1 cream where can i where to buy cafergot for migraines buy metformin online no prescription genuine levitra online generic ventolin price medicine fluoxetine 20 mg azithromycin 250 colchicine 0.6 mg tablet buy stromectol online uk allopurinol brand name in canada tetracycline 100 mg how to buy lisinopril online zithromax 500mg allopurinol 100 buy albuterol prednisolone 5mg doxycycline buy online usa lisinopril 40 mg

    Reply
  30. price of medicine valtrex buy tadalafil buy ventolin on line buy propecia amoxicillin otc antabuse tablets in india zyprexa sleep aid zoloft 50 mg strattera 10 mg tablet buy kamagra doxycycline 100 mg capsule generic lipitor 10mg cipro 500 generic wellbutrin price advair diskus price over the counter synthroid celebrex generic albuterol for sale metformin 500 mg tablet atarax 5mg

    Reply
  31. sildenafil 50 mg price medication cephalexin 500mg capsule propecia prescription australia best 120 g viagra online buy motilium canada tretinoin 0.05 cream coupon

    Reply
  32. buy disulfiram online buy accutane online canada pharmacy retin a 025 acyclovir 400 mg lipitor 20 mg generic buy suhagra 100mg cipro generic valtrex medication buy diflucan tretinoin cream where to buy

    Reply
  33. strattera 100mg generic antabuse australia prescription buy tadalafil tablets albendazole price uk buy retin a 0.025 cream 3 atarax 25 mg zoloft 50 mg tablet lipitor generic coupon doxycycline hyclate 100 mg cheap valtrex for sale suhagra 100 proventil hfa 90 mcg inhaler 25mg clomid daily synthroid 10 mcg buy propecia online without prescription generic advair from canada buy tretinoin no prescription wellbutrin 150 mg tablets celebrex 100mg metformin 500mg er

    Reply
  34. metformin price singulair brand name ventolin inhalers doxycycline 100mg advair 15 accutane discount valtrex 500 mg buy lisinopril

    Reply