PTA 數據結構 一元多項式求導 (僅供參考)
阿新 • • 發佈:2017-09-13
僅供參考 struct -o sca scanf scan -1 can 數組
請勿粘貼
輸入格式:
以指數遞降方式輸入多項式非零項系數和指數(絕對值均為不超過1000的整數)。數字間以空格分隔。
輸出格式:
以與輸入相同的格式輸出導數多項式非零項的系數和指數。數字間以空格分隔,但結尾不能有多余空格。
輸入樣例:
3 4 -5 2 6 1 -2 0
輸出樣例:
12 3 -10 1 6 0
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<queue> #include<cmath> using namespace std; struct node { int m,n; }; const int maxn=1010; node res[maxn]; //思路依舊是 用數組下標代表指數 int main() { int a,b; int num=0; while(scanf("%d%d",&a,&b)!=EOF) { res[num].m=a*b; if(abs(b)) { res[num].n=b-1; num++; } } if(num==0) cout<<0<<" "<<0<<endl; for(int i=0;i<num;i++) { if(i==num-1) cout<<res[i].m<<" "<<res[i].n<<endl; else cout<<res[i].m<<" "<<res[i].n<<" "; } }
PTA 數據結構 一元多項式求導 (僅供參考)