简单模拟题 注意细节
暴力暴力
#include <iostream>
using namespace std;
int arr[100];
int main()
{
int n;
cin>>n;
int flag = n;
for(int i = 0; i <= n; i++)
{
cin>>arr[i];
}
for(int i = 0; i <= n; i++, flag--)
{
if(i == 0)
{
if(arr[i] != 0)
{
if(arr[i] == 1)
{
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
else
{
cout<<'1';
}
}
else if(arr[i] == -1)
{
cout<<'-';
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
else
cout<<'1';
}
else
{
cout<<arr[i];
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
}
}
}
else
{
if(arr[i] != 0)
{
if(arr[i] == 1)
{
cout<<'+';
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
else
{
cout<<'1';
}
}
else if(arr[i] == -1)
{
cout<<'-';
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
else
cout<<'1';
}
else
{
if(arr[i] > 0)
cout<<'+';
cout<<arr[i];
if(flag != 0)
{
if(flag == 1)
{
cout<<'x';
}
else
{
cout<<"x^"<<flag;
}
}
}
}
}
}
return 0;
}