题目链接:NOJ2106
类型:模拟水题
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
//freopen("in.txt", "r+", stdin);
//freopen("out.txt", "w", stdout);
int n, a[100 + 5];
cin >> n;
int num = n, i;
for(i = 1; i <= n + 1; ++i)
cin >> a[i];
for(i = 1; i <= n + 1 ; ++i) {
if(i == n + 1 && a[i] > 0) {
cout << "+" << a[i] << endl;
continue;
}
if(i == n + 1 && a[i] == 0) {
cout << endl;
continue;
}
if(i == n + 1 && a[i] < 0) {
cout << a[i] << endl;
continue;
}
if(i == n && a[i] > 0) {
if(a[i] == 1) {
cout << "+x";
continue;
}
cout << "+" << a[i] << "x";
continue;
}
if(i == n && a[i] == 0) {
continue;
}
if(i == n && a[i] < 0) {
if(a[i] == -1) {
cout << "-x";
continue;
}
cout << a[i] << "x";
continue;
}
if(a[i] == 1 && i != 1) {
cout << "+x^" << num-- ;
continue;
}
if(a[i] == -1) {
cout << "-x^" << num--;
continue;
}
if(a[i] > 0 && i == 1) {
if(a[i] == 1) {
cout << "x^" << num--;
continue;
}
cout << a[i] << "x^" << num--;
continue;
}
if(a[i] > 0 && i > 1) {
if(a[i] == 1) {
cout << "+x^" << num--;
continue;
}
cout << "+" << a[i] << "x^" << num--;
continue;
}
if(a[i] < 0) {
if(a[i] == -1) {
cout << "-x^" << num--;
continue;
}
cout << a[i] << "x^" << num--;
continue;
}
if(a[i] == 0) {
num--;
continue;
}
}
return 0;
}