您的位置:首页 > 其它

UVa 498 - Polly the Polynomial

2014-10-29 17:33 337 查看
题目:一直多项式的系数,求不同的x对应多项式的值。

分析:数学题,简单题。直接代入多项式计算即可。

说明:注意输入格式。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

int temp,c[10000]; 

int main()
{
	int n;
	while ((temp = getchar()) != EOF) {
		int count = 0;
		while (temp != '\n') {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&c[count ++]);
			}
			temp = getchar();
		}
		int flag = 0,data,sum;
		temp = getchar();
		while (temp != '\n') {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&data);
				sum = 0;
				for (int i = 0 ; i < count ; ++ i) {
					sum *= data;
					sum += c[i];
				}
				if (flag) printf(" ");
				printf("%d",sum);
				flag = 1;
			}
			temp = getchar();
		}
		printf("\n");
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: