PAT 07-2 A + B and C, pat07-2
There are two noteworthy points: 1. The use of variable-length arrays (VLA), I did not expect that OJ on PAT actually supports C99, it was useless at the beginning, look at other people's, since, I don't like it very much. It doesn't mean to assign a 0 in declaration like an ordinary array so that all elements are initialized to zero. So I understand it a little. 2. For long integer formatting input and output, "ll" must be inserted in the middle of "% d". So, forget it. It is more convenient to define a temporary variable. The question setting requirements and code implementation are as follows:
/* Name: Copyright: Author: Date: 01/04/15 Description: Three integers A, B, and C in the given range [-231,231, determine whether A + B is greater than C. Input Format: enter 1st rows to give a positive integer T (<= 10), which is the number of test cases. Then, the T group test cases are given. Each group occupies one row and A, B, and C are given in sequence. Integers are separated by spaces. Output Format: for each group of test cases, "Case # X: true" is output in one row if A + B> C; otherwise, "Case # X: false" is output ", X indicates the number of the test case (starting from 1 ). Input sample: 41 2 32 3 42147483647 0 21474836460-2147483648-2147483647 output sample: Case #1: falseCase #2: trueCase #3: trueCase #4: false */# include <stdio. h> int main () {// freopen ("in.txt", "r", stdin ); // for test // printf ("% d \ n", sizeof (int), sizeof (long), sizeof (long )); // for check int I, T, A, B, C; long tmp; scanf ("% d", & T); int result [T]; // for (I = 0; I <T; I ++) // for check // printf ("% d", result [T]); for (I = 0; I <T; I ++) {scanf ("% d", & A, & B, & C ); tmp = (long) A + B; if (tmp> C) result [I] = 1; else result [I] = 0;} for (I = 0; I <T; I ++) {printf ("Case # % d:", I + 1); if (result [I]) printf ("true \ n "); else printf ("false \ n");} // fclose (stdin); // for test return 0 ;}