当前位置:网站首页>PAT 乙等 1010 C语言
PAT 乙等 1010 C语言
2022-06-23 04:11:00 【章鱼bro】
1010. 一元多项式求导 (25)
设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)
输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。
输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。
输入样例:3 4 -5 2 6 1 -2 0输出样例:
12 3 -10 1 6 0
思路:此题的坑在于理解“零多项式”,零多项式是指f(x) = 0 * (x^0),如果f(x)中含有任何非零次的项都不能称为零多项式。所以在多项式含有非零次项的时候就可忽略零次项,比如题目最后 "-2 0" 在求导后就不必再输出“0 0”。而如果多项式求导之后只有"0 * x^0"就得输出“0 0”
一、起始变量
1.coefficient系数
2.index指数
3.flag表示是否为第一个输入
二、运算
1.没有准确的输入次数,故只能使用while或者do-while。
2.当没有键入回车时,每次输入一个系数和一个指数。
3.先判断是否flag是否为1,为1表示第一次输入,在此基础上判断指数是否为0,为零直接退出循环,在结尾判断处输出“0 0”
三、代码
#include "stdio.h"
int main()
{
int coefficient;
int index;
int flag = 1;//标记是否为第一个输入
do{
scanf("%d %d",&coefficient, &index);
if(flag)
{
if(index != 0)
{
printf("%d %d",coefficient * index, index - 1);
flag = 0;
}
else
{
break;
}
}
else
{
if(index == 0)
break;
else
printf(" %d %d",coefficient * index, index - 1);
}
}while(getchar() != '\n');
if(flag)
{
printf("0 0");
}
return 0;
}边栏推荐
- Win software - (net framework) processed the certificate chain but terminated in a root certificate that is not trusted by the trusted provider
- Mobile power fast charging qc3.0 scheme chip ip5318 fast charging scheme
- 数字化工厂建设可划分为三个方面
- 制造业数字化转型存在问题及原因分析
- 数字藏品——新的投资机遇
- MySQL面试真题(二十六)——滴滴2020年笔试题
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机
- Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
- Opportunities and challenges of digital collections from the perspective of technology development team
- 低成本5W无线充电器方案FS68001B简便充电芯片
猜你喜欢

Raspberry pie assert preliminary exercise

SIFT feature point extraction

数字藏品火热背后需要强大的技术团队支持 北方技术团队

What does the English letter PC mean? What does the Internet PC mean

How to move the software downloaded from win11 app store to the desktop

Skill self check | do you know these 6 skills if you want to be a test leader?

Lottery DDD code
![[opencv450] inter frame difference method](/img/ad/c8a56e27d78cea581deb1874620613.png)
[opencv450] inter frame difference method

数字藏品赋能实体产业释放了哪些利好?

MySQL面试真题(二十六)——滴滴2020年笔试题
随机推荐
数字藏品——新的投资机遇
STC 32比特8051單片機開發實例教程 一 開發環境搭建
C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
MySQL面试真题(二十八)——案例-通讯运营商指标分析
华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)
【owt】owt-client-native-p2p-e2e-test vs2017构建 6:修改脚本自动生成vs工程
MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选
Ip6809 three coil 15W wireless charging transmitter scheme IC British chip
@jsonfield annotation in fastjson
What if win11 cannot record audio? Solution of win11 unable to input sound
Wechat applet: Star Trek spaceship ticket production and generation
ORB_SLAM2运行
Wechat applet: a new interesting test
数字藏品赋能实体产业释放了哪些利好?
电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办
数字藏品市场才刚刚开始
英文字母pc是什么意思,互联网的pc指的是什么
FS4059A与FS5080E充电芯片的区别