PAT 07-2 A + B and C, pat07-2

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.