PAT乙级 1010 一元多项式求导 (25分)

设计函数求一元多项式的导数。(注:x^n(n为整数)的一阶导数为nx^{n−1}。) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。 输出格式: 以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 0 0。 输入样例: 3 4 -5 2 6 1 -2 0 输出样例: 12 3 -10 1 6 0 注意点 用 while……EOF 的格式来读入系数和指数(黑框中触发 EOF 要按 ctrl + Z,并回车) 经测试,该题的指数都是非负整数 求导必须从低次项枚举到高次项,否则结果可能为出错 在求导后,当前系数必须清空为0,否则当前无法被后面覆盖 如果求导之后没有任何非零项,需要输出 0 0 #include <cstdio> const int maxn = 1001; int main() { int n[maxn] = {0}, c, e, cnt = 0; while (scanf("%d%d", &c, &e) != EOF) { n[e] = c; } n[0] = 0; for (int i = 1; i < maxn; i++) { n[i - 1] = i * n[i]; n[i] = 0; if (n[i - 1] != 0) { cnt++; } } if (cnt == 0) { printf("0 0"); } else { for (int i = maxn - 1; i >= 0; i--) { if (n[i] != 0) { printf("%d %d", n[i], i); cnt--; if (cnt != 0) { printf(" "); } else { break; } } } } return 0; }

March 17, 2020 · 1 min

PAT甲级 1065 A+B and C (64bit) (20分)

Given three integers A, B and C in [−2^63,2^63], you are supposed to tell whether A+B>C. Input Specification: The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces. Output Specification: For each test case, output in one line Case #X: true if A+B>C, or Case #X: false otherwise, where X is the case number (starting from 1). ...

March 15, 2020 · 2 min

PAT甲级 1014 Waiting in Line (30分)

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are: The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line. Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number. Customer[i] will take T[i] minutes to have his/her transaction processed. The first N customers are assumed to be served at 8:00am. Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done. ...

March 8, 2020 · 4 min