# Chapter I preliminary programming

## a master hand 's first small display

1. Output a line of "Hello World" on the screen and wrap it.

#include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; }

2. Calculation questions - 1 and 1.0

Calculation 1 + 1 / (1 + 1 / (1 + 1 / 5))

#Method 1 #include <iostream> #Include < iomanip > / / Please add this line using namespace std; int main() { cout<< fixed << setprecision(4) << 1.0+1.0/(1.0+1.0/(1.0+1.0/5))<<endl; // fixed and setprecision (...) are format controllers, // Fixed means to output floating-point numbers in fixed-point format (other formats include scientific counting method) // Setprecision (4) means that 4 digits are reserved after the decimal point when outputting floating-point numbers return 0; } #Method 2 #include <iostream> #include <iomanip> using namespace std; int main() { printf("%.4f",1.0+1.0/(1.0+1.0/(1.0+1.0/5))); return 0; }

3. Calculation problem - trigonometric function

[Title Description]

Calculate the value of y in the following formula

#include <iostream> #Include < iomanip > / / Please add this line #include<cmath> using namespace std; int main() { cout<< fixed << setprecision(5) << pow(sin(3.14159/4),2) + sin(3.14159/4)*cos(3.14159/4) - pow(cos(3.14159/4),2)<<endl; // fixed and setprecision (...) are format controllers, // Fixed means to output floating-point numbers in fixed-point format (other formats include scientific counting method) // Setprecision (4) means that 4 digits are reserved after the decimal point when outputting floating-point numbers return 0; } #Method 2: #include<cstdio> #include<cmath> int main() { printf("%.5f",pow(sin(3.14159/4),2) + sin(3.14159/4)*cos(3.14159/4) - pow(cos(3.14159/4),2)); return 0; }

# Chapter 2 variables and algebraic thinking

## a master hand 's first small display

1. Basic operation

[Title Description]

Xiao Ming drew a round cake. The radius of this cake is 2.52384. How big is the area of this cake? (pi = 3.1415926)

#include <iostream> #include <iomanip> using namespace std; int main() { float r=2.52384; float pi=3.1415926; float s; cout<< fixed << setprecision(4) << pi*r*r <<endl; return 0; }

2. Acceleration

[Title Description]

Small I performs uniform acceleration. The initial velocity is 0 m/s. After t seconds, the velocity is v m/s. what is the acceleration (m/s^2)?

[enter description]

Enter two integers V, t. (0 < v, t <= 1000)

[output description]

Output the acceleration of the object with 4 decimal places.

3. Find the area of the triangle

[Title Description]

Given the length of the three sides of a triangle (meeting the composition conditions of the triangle), calculate the area of the triangle.

[enter description]

The input has only one line, which is three real numbers a, B, c (a > 0, b > 0, c > 0), representing the side lengths of the three sides of the triangle.

[output description]

The output has only one line, which is a real number S (accurate to two decimal places), representing the area of the triangle.

#include <iostream> #include <iomanip> #include<cmath> using namespace std; int main() { float a,b,c; cin >>a>>b>>c; float p=(a+b+c)/2; float s=sqrt(p*(p-a)*(p-b)*(p-c)); cout<< fixed << setprecision(2) << s <<endl; return 0; }

# Logical reasoning and enumeration problem solving

## a master hand 's first small display

1. [Title Description]

Six suspects were arrested in the baswick murder. Their confessions are as follows:

A: I'm not a criminal

B: One of A and C is A criminal

C: A and B lied

D: C and F lied

E: Of the other five, only A and D told the truth

F: I'm a criminal

Only half of them told the truth and there was only one murderer.

The answer to this question is not unique. Please program to find out all possible killers.

[enter description]

nothing

[output description]

Output all answers in alphabetical order. Each line is represented as an answer.

#include <iostream> using namespace std; int main() { for (int criminal = 1; criminal <= 6; criminal++)//loop { int count = 0; if (criminal!= 1) count++; if (criminal == 1||criminal == 3) count++; if (criminal != 6) count++; if (criminal != 1 && criminal != 3 && criminal != 6) count++; if (criminal == 6) count++; if (count == 3) { if (criminal == 1) cout << "A" << endl; else if (criminal == 2) cout << "B" << endl; else if (criminal == 3) cout << "C" << endl; else if (criminal == 4) cout << "D" << endl; else if (criminal == 5) cout << "E" << endl; else if (criminal == 6) cout << "F" << endl; } } return 0; }

2. Print triangles

[Title Description]

Please program a solid isosceles right triangle with output length n.

[enter description]

Enter an integer n. (0 < n <= 10)

[output description]

Outputs a solid isosceles right triangle of length n.

# There is no problem in running, but there is a problem in submitting. Do you know the reason? The code is as follows?

#include <iostream> using namespace std; int main() { int i=0,j=0,n; cin>>n; for (i=0;i<=n;i++) { for (j=n-i+1;j<=n;j++) { cout<<"*"; } cout<<endl; } return 0; }

3. Judge leap year

[Title Description]

Enter a year to determine whether it is a leap year.

[enter description]

Enter an integer a. (1000 <= a <= 10000)

[output description]

If it is a leap year, output "YES", otherwise output "NO".

#include <iostream> using namespace std; int main() { int year; cin >> year; if (((year%400)==0)||(((year%100)!=0))&&((year%4)==0)) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }

# Chapter IV screening method and search

## a master hand 's first small display

1. Joseph Ring

[Title Description]

Joseph problem (sometimes called Josephus permutation) is a problem that appears in computer science and mathematics. In computer programming algorithms, similar problems are also called Joseph rings.

3. Quality factor decomposition

[Title Description]

Decompose the prime factors of n positive integers greater than 1, sort them from small to large, and output them in equation format.

[enter description]

The first line is an integer n, which represents the number of prime factors to be decomposed. (1<=n<=100)

Lines 2 to n+1 are n positive integers x that need to be decomposed_ i. (1 < x_i < 10^9)

[output description]

There are n lines in total. Each line decomposes the equation obtained by the prime factor, and the factors are arranged from small to large.