PAT (Basic Level) Practice (中文)1010 一元多项式求导 (25 分)
生活随笔
收集整理的這篇文章主要介紹了
PAT (Basic Level) Practice (中文)1010 一元多项式求导 (25 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
設計函數求一元多項式的導數。(注:x?n?? (n為整數)的一階導數為nxn?1?? 。)
輸入格式:
以指數遞降方式輸入多項式非零項系數和指數(絕對值均為不超過 1000 的整數)。數字間以空格分隔。
輸出格式:
以與輸入相同的格式輸出導數多項式非零項的系數和指數。數字間以空格分隔,但結尾不能有多余空格。注意“零多項式”的指數和系數都是0,但是表示為 0 0。
輸入樣例:
3 4 -5 2 6 1 -2 0
輸出樣例:
12 3 -10 1 6 0
C++實現
#include <iostream> using namespace std; int main() {int a,n,flag=0;while (cin>>a>>n){if (n!=0){if (flag==1) cout<<' ';cout<<a*n<<' '<<n-1;flag=1;}}if (flag==0) cout<<"0 0";return 0; }python實現
n=input().split() a=list(map(int,n)) i=0 c=[] while not i==len(a):m=a[i]*a[i+1]b=a[i+1]-1if m:if a[i+1]==0 and not (a[i]==0):passelif b==-1 and a[i]==0:m=0b=0c.append(str(m))c.append(str(b))else:c.append(str(m))c.append(str(b))i+=2 if not(len(c)):print('0 0') else:print(' '.join(c).strip())總結
以上是生活随笔為你收集整理的PAT (Basic Level) Practice (中文)1010 一元多项式求导 (25 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PAT (Basic Level) Pr
- 下一篇: PAT (Basic Level) Pr