UVa 498

题目:一直多项式的系数,求不同的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 != '
') {
			if (temp == '-' || temp >= '0' && temp <= '9') {
				ungetc(temp, stdin);
				scanf("%d",&c[count ++]);
			}
			temp = getchar();
		}
		int flag = 0,data,sum;
		temp = getchar();
		while (temp != '
') {
			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("
");
	}
	return 0;
}


原文地址:https://www.cnblogs.com/lytwajue/p/6759329.html