Nylon @ 2024-03-28 23:10:02
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int i,j;
cin >> n;
vector<int> arr(n+1);
for (i=n;i>=0;i--){
cin >> arr[i];
}
for (i=n;i>=0;i--){
if (arr[i]>0){
if(i==n){
cout << arr[i] << "x^" << i;
}
if(i==0){
cout << "+" << arr[i];
}
if(i!=n && i!=0){
cout << "+" << arr[i] << "x^" << i;
}
}
if (arr[i]<0){
if(i==n){
cout << arr[i] << "x^" << i;
}
if(i==0){
cout << arr[i];
}
if(i!=n && i!=0){
cout << arr[i] << "x^" << i;
}
}
}
cout << endl;
return 0;
}
by chenjiayicxq821411 @ 2024-06-15 08:55:23
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,a;
cin>>n;
for(int i=n;i>-1;i--)
{
cin>>a;
if(a)
{
if(i!=n&&a>0) cout<<"+";
if(abs(a)>1||i==0) cout<<a;
if(a==-1&&i) cout<<"-";
if(i>1) cout<<"x^"<<i;
if(i==1) cout<<"x";
}
}
}