#include <stdio.h> int main() { char s[10000]; while (gets(s) != NULL) { int i, j, l, n = 0, times = 0, cal = 0, c[10000]; for (l = 0; ; l++) { if (s[l] == ' ' || !s[l]) { if (n) cal *= -1; c[times++] = cal; n = 0; cal = 0; if (!s[l]) break; } else if (s[l] == '-') { n = 1; } else { cal = cal * 10 + s[l] - '0'; } } gets(s); int x = 0, first = 0, sum = 0, temp; for (l = 0; ; l++) { if (s[l] == ' ' || !s[l]) { if (first) printf(" "); first = 1; if (n) x *= -1; sum = 0; for (i = 0; i < times; i++) { temp = c[i]; for (j = 0; j < (times - 1 - i); j++) temp *= x; sum += temp; } printf("%d", sum); x = 0; n = 0; if (!s[l]) break; } else if (s[l] == '-') { n = 1; } else { x = x * 10 + s[l] - '0'; } } puts(""); } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2012年9月4日
UVa 498 - Polly the Polynomial
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言