A simulation question, mainly pay attention to the handling of details.
Write it again, And, ym .....
Wa yourself for one night .....
You can understand the specific method by reading the annotations...
# Include <stdlib. h> <br/> # include <stdio. h> <br/> # include <string. h> </P> <p> typedef _ int64 type; <br/> type XX [15]; <br/> char STR [10005], s [10005]; <br/> void get (int x) <br/>{< br/> _ int64 I, T = x; <br/> XX [0] = 1; <br/> for (I = 1; I <= 10; I ++) <br/>{< br/> XX [I] = T; <br/> T * = x; <br/>}</P> <p> type solve () <br/>{< br/> type ans, C1, C2, N; <br/> int I, Len = strlen (s ); <br/> int op = 0; // + 1 |-2 <br/> bool flag, flag2; <br/> I = 0, C1 = 0, C2 = 0, n = 0, ANS = 0, flag = false; <br/> while (I <= Len) <br/> {<br/> If (s [I] = '+' | s [I] = '-' | s [I] = 0 x 00) <br/>{< br/> C2 = XX [N]; <br/> // calculate by operator <br/> If (OP = 1) <br/>{< br/> ans + = (C1 * C2); <br/> flag = false; <br/> // printf ("Ans: % i64d/N ", C1 * C2); <br/>}< br/> If (OP = 2) <br/>{< br/> ANS-= (C1 * C2); <br/> flag = false; <Br/> // printf ("Ans:-% i64d/N", C1 * C2 ); <br/>}< br/> // first read the operator <br/> If (s [I] = '+') OP = 1; <br/> If (s [I] = '-') OP = 2; <br/> I ++; <br/> C1 = 0, C2 = 0, n = 0; <br/>} else {<br/> // read the number before x <br/> If (s [I]> = '0' & S [I] <= '9 ') <br/>{< br/> flag = true; <br/> C1 = C1 * 10 + s [I]-'0'; <br/> I ++; <br/>}</P> <p> If (s [I] = 'X ') <br/> {<br/> // The prefix is null <br/> If (C1 = 0 & flag = false) <br/> C1 = 1; <B R/> I ++; <br/> // The suffix of X is blank <br/> If (s [I]! = '^') <Br/> n = 1; <br/>}</P> <p> If (s [I] = '^ ') <br/>{< br/> I ++; <br/> // read the number after ^ <br/> while (1) <br/> {<br/> If (s [I] = '+' | s [I] = '-' | s [I] = 0 x 00) <br/> break; <br/> N = N * 10 + s [I]-'0'; <br/> I ++; <br/>}< br/> // printf ("# % d/N", ANS ); <br/> return ans; <br/>}< br/>/* <br/> */<br/> int main () <br/>{< br/> int X; <br/> while (scanf ("% d % s", & X, STR )! = EOF) <br/>{< br/> get (x); <br/> If (STR [0]! = '-') <Br/>{< br/> // All string prefixes start with symbols. Better Processing <br/> S [0] = '+ '; <br/> strcpy (& S [1], STR); <br/>}else {<br/> strcpy (S, STR ); <br/>}< br/> printf ("% i64d/N", solve (); <br/>}< br/> return 0; <br/>}
Polynomial problem <br/> time limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) <br/> total submission (s ): 216 accepted submission (s): 101 </P> <p> Problem description <br/> we have learned how to obtain the value of a polynomial when we were a middle school student. if f (x) is a polynomial of degree n, we can let </P> <p> if we have X, we can get f (x) easily. but a computer can not understand the expression like above. so we had better make a program to obtain f (x ). </P> <p> input <br/> there are multiple cases in this problem and ended by the EOF. in each case, there are two lines. one is an integer means x (0 <= x <= 10000), the other is an expression means f (x ). all coefficients AI (0 <= I <= N, 1 <= n <= 10,-10000 <= AI <= 10000) are integers. A correct expression maybe likes <br/> 1003x ^ 5 + 234x ^ 4-12x ^ 3-2x ^ 2 + 987x-1000 </P> <p> output <br/> for each test case, there is only one integer means the value of f (x ). </P> <p> sample input <br/> 3 <br/> 1003x ^ 5 + 234x ^ 4-12x ^ 3-2x ^ 2 + 987x-1000 </P> <p> sample output <br/> 264302 </P> <p> notice that the writing habit of Polynomial f (x) is usual such as <br/> x ^ 6 + 2x ^ 5 + 3x ^ 4 + 4x ^ 3 + 5x ^ 2 + 6x + 7 <br/>-x ^ 7-5x ^ 6 + 3x ^ 5-5x ^ 4 + 20x ^ 3 + 2x ^ 2 + 3X + 9 <br/> x + 1 <br/> x ^ 3 + 1 <br/> X ^ 3 <br/>-x + 1 etc. any results of middle process are in the range from-1000000000 to 1000000000. <br/>