UVa 10268 - 498-bis Solution

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
string s;
vector<int> a;
int x;
long long int poly(){
    long long int ans,n=a.size()-1;
    ans=a[0]*n;
    for(int i=1;i<a.size()-1;i++){
        ans=ans*x+a[i]*(n-i);
    }
    return ans;
}
void conv(){
    stringstream ss(s);
    int y;
    while(ss>>y){
        a.push_back(y);
    }
}
int main(){
    ios::sync_with_stdio(0);
    while(ws(cin)&&!cin.eof()){
        cin>>x;
        a.clear();
        ws(cin);
        getline(cin,s);
        conv();
        cout<<poly()<<endl;
    }
}

Comments