记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 224.0 KiB
#2 Accepted 1ms 220.0 KiB
#3 Accepted 1ms 232.0 KiB
#4 Accepted 1ms 224.0 KiB
#5 Accepted 1ms 220.0 KiB

代码

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int n;

int main()
{
	cin>>n;
	int xis[n+2];
	for(int i=1;i<=n+1;++i)
		cin>>xis[i];
	if(xis[1]<0&&xis[1]!=-1)
		cout<<"-"<<abs(xis[1])<<"x^"<<n;
	else if(xis[1]>0&&xis[1]!=1)
		cout<<xis[1]<<"x^"<<n;
	else if(xis[1]==1)
		cout<<"x^"<<n;
	else if(xis[1]==-1)
		cout<<"-x^"<<n;
	for(int i=n-1,j=2;i>=2;--i,++j)
	{
		if(xis[j]<0&&xis[j]!=-1)
			cout<<"-"<<abs(xis[j])<<"x^"<<i;
		else if(xis[j]>0&&xis[j]!=1&&j==2&&xis[j-1]!=0)
			cout<<"+"<<xis[j]<<"x^"<<i;
		else if(xis[j]>0&&xis[j]!=1&&j==2&&xis[j-1]==0)
			cout<<xis[j]<<"x^"<<i;
		else if(xis[j]>0&&xis[j]!=1&&j!=2)
			cout<<"+"<<xis[j]<<"x^"<<i;
		else if(xis[j]==1)
			cout<<"+"<<"x^"<<i;
		else if(xis[j]==-1)
			cout<<"-x^"<<i;
	}
	if(xis[n]<0&&xis[n]!=-1) 
		cout<<"-"<<abs(xis[n])<<"x";
	else if(xis[n]>0&&xis[n]!=1)
		cout<<"+"<<xis[n]<<"x";
	else if(xis[n]==1)
		cout<<"+"<<"x";
	else if(xis[n]==-1)
		cout<<"-x";
	if(xis[n+1]<0&&xis[n+1]!=-1)
		cout<<"-"<<abs(xis[n+1]);
	else if(xis[n+1]>0&&xis[n+1]!=1)
		cout<<"+"<<xis[n+1];
	else if(xis[n+1]==1)
		cout<<"+1";
	else if(xis[n+1]==-1)
		cout<<"-1";
	return 0;
}

信息

递交者
类型
递交
题目
P1010 写多项式(Writing the polynomial)
语言
C++
递交时间
2019-07-23 17:05:26
评测时间
2019-07-23 17:05:26
评测机
分数
50
总耗时
6ms
峰值内存
232.0 KiB