-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path498.cpp
101 lines (67 loc) · 1.59 KB
/
498.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define MAXN 10000000
using namespace std;
int cntC, cntX;
int C[MAXN], X[MAXN];
char text[MAXN];
void split_numbers( int what ) {
int number = 0;
bool fl = false;
bool neg = false;
for ( int i = 0; text[i] != '\0'; ++i ) {
if ( text[i] >= '0' && text[i] <= '9' ) {
number *= 10;
number += text[i]-'0';
}else if ( text[i] == '-' ) {
neg = true;
}else if ( text[i] == ' ' ) {
if ( neg ) {
number *= -1;
}
if ( what == 1 ) {
C[++cntC] = number;
}else {
X[++cntX] = number;
}
number = 0;
fl = false;
neg = false;
}
}
if ( neg ) {
number *= -1;
}
if ( what == 1 ) {
C[++cntC] = number;
}else {
X[++cntX] = number;
}
}
int calc( int n ) {
int ret = 0;
int x = 1;
for ( int i = cntC; i >= 1; --i ) {
ret += C[i] * x;
x *= X[n];
}
return ( ret );
}
int main( ) {
while ( gets( text ) ) {
cntC = 0;
split_numbers( 1 );
gets( text );
cntX = 0;
split_numbers( 2 );
printf( "%d", calc( 1 ) );
for ( int i = 2; i <= cntX; ++i ) {
printf( " %d", calc( i ) );
}
putchar( '\n' );
}
return 0;
}