第7
、8
、9
个测试点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;
}