Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Tittle: 10268 - 498-bis
- * Author: Cheng-Shih, Wong
- * Date: 2015/05/02
- */
- // include files
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <vector>
- using namespace std;
- // definitions
- #define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
- #define clr(x,v) memset( x, v, sizeof(x) )
- typedef vector<int> VI;
- // declarations
- int x;
- int ans;
- // functions
- void solve( void )
- {
- static int tmp, base, cnt;
- static VI bucket;
- bucket.clear();
- scanf( "%d", &tmp );
- bucket.push_back(tmp);
- while( getchar()!='\n' ) {
- scanf( "%d", &tmp );
- bucket.push_back(tmp);
- }
- ans = 0;
- cnt = base = 1;
- for( int i = bucket.size()-2; i>=0; --i ) {
- ans += cnt*bucket[i]*base;
- ++cnt;
- base *= x;
- }
- printf( "%d\n", ans );
- }
- // main function
- int main( void )
- {
- // input
- while( scanf( "%d", &x )==1 ) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement