PAT乙级 1010 一元多项式求导

这个题挺迷的

如果同时存在多项式部分,常数部分不用输出  例: 输入 2 3 1 0  输出 6 2

如果只存在常数部分,还要输出常数项的指数(0),零多项式是这个的一种  例: 输入 1 0  输出 0 0

 

#include <iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
    int num[10000];
    int a,b;
    int n=0;

    int flag=0;  //判定之前有没有输出,判定是不是零多项式

    while(cin>>a>>b)
    {
        if(flag==0&&b==0)  //用来判定是不是只有常数项输入
        {
            cout<<0<<" "<<0;
            return 0;
        }
        num[n]=a*b;
        n++;
        flag=1;
        if(b==0)      //b==0代表这个项是常数项,输出时常数项不输出
        {
            n--;
            break;
        }

        num[n]=b-1;
        n++;
    }
    for(int i=0;i<n;i++)
    {
        cout<<num[i];
        if(i+1!=n)
            cout<<" ";
    }
    return 0;
}

 

posted @ 2021-10-29 13:35  Mr。atopos  阅读(41)  评论(0)    收藏  举报