Cuimenghao @ 2024-02-09 09:50:09
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a[102], b = 0;
cin >> n;
for (int i = 0; i <= n ; i++) {
cin >> a[i];
}
for (int i = 0; i <= n - 1; i++) {
if (a[i] == 0) {
continue;
} else if (a[i] == - 1) {
cout << "-" << "x" << "^" << n - i;
if (a[i + 1] > 0) {
cout << "+";
}
} else if ( a[i] < 0 && i != - 1) {
cout << a[i] << "x" << "^" << n - i;
if (a[i + 1] > 0) {
cout << "+";
}
} else if (a[i] == 1) {
cout << "x" << "^" << n - i;
if (a[i + 1] > 0) {
cout << "+";
}
} else {
cout << a[i] << "x" << "^" << n - i ;
if (a[i + 1] > 0) {
cout << "+";
}
}
b = i;
}
if (a[n]>0||a[n]<0) {
cout << a[n];
}
return 0;
}
by Cuimenghao @ 2024-02-09 09:51:08
还是不对
by __Tonycyt__ @ 2024-02-09 09:55:26
首先36行改成 cout << "+" << a[n];
才能过样例1
by __Tonycyt__ @ 2024-02-09 09:55:39
然后我再找找
by Cuimenghao @ 2024-02-09 09:58:23
还是20分
by __Tonycyt__ @ 2024-02-09 09:58:25
然后35行 if (a[n]>0||a[n]<0)
改成 if (a[n]!=0)
会运行快一些(!=
就是不等于)
by __Tonycyt__ @ 2024-02-09 09:58:43
@Cuimenghao 我知道,我在找了
by __Tonycyt__ @ 2024-02-09 09:59:22
我下载个数据点看一眼吧
by __Tonycyt__ @ 2024-02-09 10:01:14
读入之后加一个特判。
if (n == 0){
cout << a[0];
return 0;
}
by __Tonycyt__ @ 2024-02-09 10:02:47
这样能多AC一个点(虽然这个点0分,但是你不AC这个点就算你AC其他所有点系统也算你不通过)
by Cuimenghao @ 2024-02-09 10:04:35
OK