璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup1067
problems
名称多项式输出
题目编号2009 NOIP PJ T1
题目链接luogu.com.cn/…
来源CCF
算法分类模拟
难易程度容易

多项式输出

想法

认真归类与思考,如何简化模拟流程。

  1. 读入0,不进行处理
  2. 单独处理符号,让负数在首位输出符号,让正数在非首位输出符号。
  3. 输出系数,末项均可输出,非末项的1不能输出。
  4. 输出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 由 温婕莺