V_HAPPY666 @ 2024-08-22 14:46:05
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n;
cin>>n;
int xishu[n+1],k=n;
for(int i=0;i<=n;i++)cin>>xishu[i];
//最高次数项
if(abs(xishu[0])==1)
{
if(xishu[0]==-1)cout<<'-';
}
else cout<<xishu[0];
cout<<"x^"<<n--;
//中间部分
for(int i=1;i<k;i++)
{
int x=xishu[i];
if(x>0)
{
cout<<'+';
if(x==1)
{
if(n>1)cout<<"x^"<<n;
else cout<<'x';
//continue;
}
else
{
if(n>1)cout<<x<<"x^"<<n;
else cout<<x<<'x';
//continue;
}
}
else if(x<0)
{
if(x==-1)
{
if(n>1)cout<<"-x^"<<n;
else cout<<"-x";
//continue;
}
else
{
if(n>1)cout<<x<<"x^"<<n;
else cout<<x<<'x';
//continue;
}
}
n--;
}
//系数
if(xishu[k]>0)cout<<'+';
if(xishu[k]!=0)cout<<xishu[k];
return 0;
}
by V_HAPPY666 @ 2024-08-22 14:46:30
谁能告诉我测试点1的数据是什么?
by 违规用户名K&xs3Z^ @ 2024-08-22 14:48:13
@V_HAPPY666 宝贵的一次下载。。求关
in:
0
1
out:
1
by V_HAPPY666 @ 2024-08-22 14:51:20
@违规用户名K&xs3Z^ 谢谢,关注了
by V_HAPPY666 @ 2024-08-22 14:51:43
@违规用户名K&xs3Z^ 没有看到下面n可以为0
by 违规用户名K&xs3Z^ @ 2024-08-22 14:52:49
@V_HAPPY666 嗯嗯 刚给你改到一半(悲
by V_HAPPY666 @ 2024-08-22 14:54:22
@违规用户名K&xs3Z^ 谢谢已经AC了
by 违规用户名K&xs3Z^ @ 2024-08-22 14:54:47
@V_HAPPY666 ok
by XIAOHAOYU1 @ 2024-09-18 18:44:44
?
#include <iostream>
using namespace std;
int main(){
int n,a;
scanf("%d", &n);
for(int i = n;i >= 0; -- i){
scanf("%d", &a);
if(a){
if(i != n && a > 0) printf("+");
if(abs(a) > 1 || i == 0) printf("%d", a);
if(a == -1 && i) printf("-");
if(i > 1) printf("x^%d", i);
if(i == 1) printf("x");
}
}
return 0;
}
似乎不需要那么长
求关