Files
python/C++专题课程/NOIP算法总结/字符串处理/多项式输出/P1067.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

20 lines
461 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int main() {
int n,a,i;
cin>>n;
for(i=n; i>=0; i--) {
//倒着输入,便于下面输出x的几次方
cin>>a;
if(a) { //判定a是否为真(即不等于0)
if(i!=n&&a>0) cout<<"+"; //i!=n,第一项不用符号
if(abs(a)>1||i==0) cout<<a;//abs是绝对值函数,最后一项或不是-1或1时输出。
if(a==-1&&i) cout<<"-"; //-1省略1
if(i>1) cout<<"x^"<<i;
if(i==1) cout<<"x"; //指数为1时省略1
}
}
return 0;
}