pat-B1010-一元多项式求导

题目链接->link

思路

  1. 这题输入输出即可以全部输入到数组中求导,再输出,又可以输入一对输出一对,两种都对,有点奇怪。
  2. 坑点有两处,一是当输入系数为0,指数为0时,直接输出0 0,因为按指数递减输入,故一定是第一组数据。
  3. 二是当系数不为0,指数不为0时,如果是第一组则输出0 0,如果是最后一组不输出。综上,在第一组和循环中都需要作判断,也是第三组数据老是不过的原因。
  4. 最后是注意输出格式即可。

代码

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

using namespace std;

int main(){
    int t,e;
    cin>>t>>e;
    if(e==0){
        cout<<0<<' '<<0;
    }
    else cout<<t*e<<' '<<e-1;
    while(cin>>t>>e){
        if(e==0)break;
        else cout<<' '<<t*e<<' '<<e-1;
    }
    return 0;
}

发布了28 篇原创文章 · 获赞 1 · 访问量 592

猜你喜欢

转载自blog.csdn.net/MichealWu98/article/details/104044314
今日推荐