MuYuMC @ 2024-06-24 22:43:46
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int A[100000];
int B[100000];
int main()
{
int n,i,h = 0;
cin >> n;
for(i = 1;i <= n + 1;i++)
{
cin >> A[i];
}
if(A[1] != 0)
{
if(A[1] > 0)
{
if(A[1] == 1)
{
cout << "x^" << n;
h = 1;
}
else
{
cout << A[1] << "x^" << n;
h = 1;
}
}
else
{
if(A[1] == -1)
{
cout << "-" << "x^" << n;
h = 1;
}
else
{
cout << A[1] << "x^" << n;
h = 1;
}
}
}
for(i = 2;i <= n;i++)
{
if(A[i] == 0)continue;
else
{
if(n - i + 1 == 0)
{
if(A[i] > 0)
{
if(h == 0)
{
cout << A[i];
h = 1;
}
else
{
cout << "+" << A[i];
}
}
else cout << A[i],h = 1;
}
else
{
if(A[i] > 0)
{
if(n - i + 1 == 1)
{
if(h == 0)
{
if(A[i] == 1)
{
cout << "x";
h = 1;
}
else
{
cout << A[i] << "x";
h = 1;
}
}
else
{
if(A[i] == 1)
{
cout << "+" << "x";
h = 1;
}
else
{
cout << "+" << A[i] << "x";
h = 1;
}
}
}
else
{
if(h == 0)
{
if(A[i] == 1)
{
cout << "x^" << n - i + 1;
h = 1;
}
else
{
cout << A[i] << "x^" << n - i + 1;
h = 1;
}
}
else
{
if(A[i] == 1)
{
cout << "+" << "x^" << n - i + 1;
}
else
{
cout << "+" << A[i] << "x^" << n - i + 1;
}
}
}
}
else
{
if(n - i + 1 == 1)
{
if(A[i] == -1)
{
cout << "-" << "x";
}
else
{
cout << A[i] << "x";
}
}
else
{
if(A[i] == -1)
{
cout << "-" << "x^" << n - i + 1;
}
else
{
cout << A[i] << "x^" << n - i + 1;
}
}
}
}
}
}
if(h == 0)
{
cout << A[n +1];
}
else
{
if(A[n + 1] < 0) cout << A[n + 1];
else cout << "+" << A[n + 1];
}
return 0;
}
by MuYuMC @ 2024-06-24 22:44:55
代码发错了
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int A[100000];
int B[100000];
int main()
{
int n,i,h = 0;
cin >> n;
for(i = 1;i <= n + 1;i++)
{
cin >> A[i];
}
if(A[1] != 0)
{
if(A[1] > 0)
{
if(A[1] == 1)
{
cout << "x^" << n;
h = 1;
}
else
{
cout << A[1] << "x^" << n;
h = 1;
}
}
else
{
if(A[1] == -1)
{
cout << "-" << "x^" << n;
h = 1;
}
else
{
cout << A[1] << "x^" << n;
h = 1;
}
}
}
for(i = 2;i <= n;i++)
{
if(A[i] == 0)continue;
else
{
if(n - i + 1 == 0)
{
if(A[i] > 0)
{
if(h == 0)
{
cout << A[i];
h = 1;
}
else
{
cout << "+" << A[i];
}
}
else cout << A[i],h = 1;
}
else
{
if(A[i] > 0)
{
if(n - i + 1 == 1)
{
if(h == 0)
{
if(A[i] == 1)
{
cout << "x";
h = 1;
}
else
{
cout << A[i] << "x";
h = 1;
}
}
else
{
if(A[i] == 1)
{
cout << "+" << "x";
h = 1;
}
else
{
cout << "+" << A[i] << "x";
h = 1;
}
}
}
else
{
if(h == 0)
{
if(A[i] == 1)
{
cout << "x^" << n - i + 1;
h = 1;
}
else
{
cout << A[i] << "x^" << n - i + 1;
h = 1;
}
}
else
{
if(A[i] == 1)
{
cout << "+" << "x^" << n - i + 1;
}
else
{
cout << "+" << A[i] << "x^" << n - i + 1;
}
}
}
}
else
{
if(n - i + 1 == 1)
{
if(A[i] == -1)
{
cout << "-" << "x";
}
else
{
cout << A[i] << "x";
}
}
else
{
if(A[i] == -1)
{
cout << "-" << "x^" << n - i + 1;
}
else
{
cout << A[i] << "x^" << n - i + 1;
}
}
}
}
}
}
if(A[n + 1] == 0)return 0;
else
{
if(h == 0)
{
cout << A[n +1];
}
else
{
if(A[n + 1] < 0) cout << A[n + 1];
else cout << "+" << A[n + 1];
}
}
return 0;
}
by NRDI @ 2024-06-24 23:30:09
提交记录?
by ifffer_2137 @ 2024-06-25 08:04:57
@MuYuMC 你试个 0 1
的数据就懂了