[DTOJ] 1001: rectangular circumference and area, dtoj1001

Source: Internet
Author: User

[DTOJ] 1001: rectangular circumference and area, dtoj1001

DTOJ 1001: rectangular perimeter and area solution report

  • --CoolOriginal

 

Question information:Description

If we know the length and width of a rectangle, what is the circumference and area of the rectangle?

Input

One line: two integers separated by spaces, indicating length and width

Output

One line: the circumference and area of the rectangle, separated by spaces in the middle.

Sample Input

3 4

Sample output

14 12

Prompt

Perimeter: 2 * (a + B), area: a * B

Ideas:

Define Integer Variables a and B and input them. Define the circumference of Integer Variables c = 2 * (a + B) and area s = a * B. output values c and s, note that there is a space between c and s.

My code (C ++ ):
 1 //DTOJ 1001  2 #include <iostream> 3 using namespace std; 4  5 int main() 6 { 7     int a,b,c,s; 8     cin>>a>>b; 9     c=(a+b)*2;10     s=a*b;11     cout<<c<<" "<<s;12     return 0;13 } 
Analysis:

The first line: // DTOJ 1001 a statement starting with "//" is a comment statement. It is used to annotate all texts of the row and is not executed during actual operation. You can properly comment out or comment out useless code next to the code.

The second line: # include <iostream> pre-processing command. The pre-processor processes the code before compilation. It is often used to include header files and macro definitions. This is the standard input/output stream library <iostream>.

Row 3: using namespace std; using command, which indicates that all the code that has been written here uses the std namespace. All C ++ standard resources (such as standard input cout) are in the namespace and std ::, the using command can simplify this series of troubles, but it also has some disadvantages and will be mentioned later. The C ++ statement ends with a semicolon (;), indicating that the statement ends. Use the std namespace.

Row 4: this behavior is empty. Most programmers divide the code into many parts when writing code. Each part is separated by one line. Here, the Code follows the "unwritten code style specification ".

Fifth line: int main () This is the main function main () of the program. In the OI competition, all programs require the return value of the main () function to be int type, run correctly and return 0 (return 0 ;). The main () function is the main component of the Program. All code is executed from this point.

Row 6 and row 13th: {} are attached to the function, which indicates the function content.

Row 7: int a, B, c, s; defines integer int variables a, B, c, s.

Row 8: cin> a> B; standard input cin, included in the standard input and output stream library <iostream>. The using command uses the std namespace, you do not need to add the std: prefix.> This is overloaded by the iostream class, indicating that the input data is from the standard input to the variable. Enter a and B.

Row 9 and row 10: c = (a + B) * 2; s = a * B; Value assignment statement, indicating that the value of the equal sign = following expression is assigned to the variable of the equal sign = front edge.

Row 3: cout <c <"" <s; standard output cout, similar to cin. Included in <iostream>, <is overloaded by iostream class, which means to output variable data to standard output. "" Is the string in the original output quotation marks. Here, the quotation marks contain spaces, that is, a space is output between the value of c and the value of s. Here is the value of output c, space, and s.

Row 12th: A Rough introduction to the fifth line is the standard specification of the OI competition. The value 0 here is returned to the operating system, indicating that the program runs correctly and ends.

 


This work is licensed using the knowledge sharing signature-non-commercial use-share the 4.0 international license agreement in the same way.

-- Qoreng's Funny match w

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.