您的位置:首页 > 其它

1280: Polly the Polynomial

2010-07-10 20:27 274 查看
1280: Polly the Polynomial

ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE

3s8192K452148Standard
Algebra! Remember algebra? There is a theory that as engineers progresses further and further in their studies, they lose basic math skills. This problem is designed to help you remember those basic algebra skills, make the world a better place, etc., etc.

Input

Your program should accept an even number of lines of text. Each pair of lines will represent one problem. The first line will contain a list of integers {

} which represent a set of coefficients to a polynomial expression. The order of the polynomial is n. The coefficients should be paired with the terms of the polynomial in the following manner:



The second line of text represents a sequence of values for x, {

}.

Output

For each pair of lines, your program should evaluate the polynomial for all the values of x (

through

) and output the resulting values on a single line.

Sample Input

-2
5 0 1 6
1 -1
7 6 -1

Sample Output

-2 -2 -2 -2
6 5 -2


This problem is used for contest: 107

#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
istringstream sin(str);
vector< int > a;
int n;
while(sin>>n) a.push_back(n);
//for(int i=0;i<a.size();i++) printf("%d...",a[i]);printf("/n");
str.clear();
getline(cin,str);
// cout<<str<<"........"<<endl;
istringstream fin(str);
int flag=0;
while(fin>>n)
{
//printf("%d...../n",n);
if(flag==0) flag=1;else printf(" ");
int sum=0;
for(int i=0;i<a.size();i++) sum=sum*n+a[i];
printf("%d",sum);
}
printf("/n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: