icpc:problems:luogup1067
problems | |
---|---|
名称 | 多项式输出 |
题目编号 | 2009 NOIP PJ T1 |
题目链接 | luogu.com.cn/… |
来源 | CCF |
算法分类 | 模拟 |
难易程度 | 容易 |
多项式输出
想法
认真归类与思考,如何简化模拟流程。
- 读入0,不进行处理
- 单独处理符号,让负数在首位输出符号,让正数在非首位输出符号。
- 输出系数,末项均可输出,非末项的1不能输出。
- 输出x与其次方。
代码实现
#include<cstdio> #include<cmath> int main() { int n, temp; scanf("%d", &n); for(int i = n; i >= 0; i--) { scanf("%d", &temp); if(temp == 0)continue; if(i != n || temp < 0)printf("%c", temp > 0 ? '+' : '-'); if(abs(temp) > 1 || i == 0)printf("%d", abs(temp)); if(i != 0)printf("x"); if(i > 1)printf("^%d", i); } return 0; }
/app/www/public/data/pages/icpc/problems/luogup1067.txt · 最后更改: 2024/03/14 15:07 由 温婕莺