救救70分的孩子 w
查看原帖
救救70分的孩子 w
204619
wwhOvO楼主2020/5/23 15:50

789个测试点WA。

自认为代码写的很漂亮,尽管很长

#include <bits/stdc++.h>
#define MAXN 1010

using namespace std;

int n , a[ MAXN ];

int main()
{
	cin >> n;
	for( int i = 1 ; i <= n + 1 ; i++ ) cin >> a[i];
	for( int i = 1 ; i <= n + 1 ; i++ )
	{
		if( i == 1 ) 
		{
			if( a[i] == 0 ) continue;
			else if( a[i] == 1 ) {cout << "x^" << n - i + 1 ;continue;}
			else if( a[i] == -1 ) {cout << "-x^" << n - i + 1 ;continue;}
			else if( a[i] < 0 ) {cout << a[i] << "x^" << n - i + 1 ;continue;}
			else if( a[i] > 0 ) {cout << a[i] << "x^" << n - i + 1 ;continue;}
		}
		int power = n - i + 1;
		
		if( power == 0 )
		{
			if( a[i] == 0 ) continue;
			if( a[i] > 0 ) cout << "+" << a[i] ;
			else cout << a[i] ;
			break;
		}
		else if( power == 1 )
		{
			if( a[i] == 0 ) continue;
			else if( a[i] == 1 ) cout << "+x" ;
			else if( a[i] == -1 ) cout << "-x" ;
			else if( a[i] > 0 ) cout << "+" << a[i] << "x" ;
			else cout << cout << a[i] << "x" ; 
			continue;
		}
		
		if( a[i] == 0 ) continue;
		else if( a[i] == 1 ) cout << "+x^" << power ;
		else if( a[i] == -1 ) cout << "-x^" << power ;
		else if( a[i] < 0 ) cout << a[i] << "x^" << power ;
		else if( a[i] > 0 ) cout << "+" << a[i] << "x^" << power ;
		
	}
	return 0;
}
2020/5/23 15:50
加载中...