1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<iostream> using namespace std; int main(){ int n; cin>>n; for(int i=n;i>=0;i--){ string num; bool jian=0; bool o=0; cin>>num; if(num=="0"){ continue; } if(num=="1"){ o=1; num="x"; } if(num[0]=='-'){ jian=1; if(num=="-1"){ o=1; num="-x"; } } if(i==n){ if(o){ cout<<num<<"^"<<i; }else cout<<num<<"x^"<<i; }else if(i==1){ if(jian==0){ cout<<"+"; } if(o){ cout<<"x"; }else cout<<num<<"x"; }else if(i==0){ if(jian==0&&o){ cout<<"+1"; }else if(jian&&o){ cout<<"-1"; }else if(jian==0){ cout<<"+"<<num; }else cout<<num; }else{ if(jian==0){ cout<<"+"; } if(o){ cout<<num<<"^"<<i; }else cout<<num<<"x^"<<i; } } cout<<endl; return 0; }
|