<style>
.markdown-body { max-width: 1800px; }
.orange { color: orange; }
.green { color: green; }
.red { color: red; }
section.present > div > pre > code {
max-height: 700px;
max-width: 2000px;
font-size: 16px;
}
section.present > div > blockquote > pre > code {
font-size: 16px;
}
section.present > div > blockquote > code {
font-size: 16px;
}
section.present > div > blockquote {
margin: calc(var(--r-block-margin) / 2) auto;
width: 800px;
}
h3 > span {
font-size: 60px;
color: #ff88ff;
}
h4 > span {
font-size: 60px;
color: #ee4400;
}
h5 > span {
font-size: 27px;
color: orange;
}
section.present > div > blockquote > p {
margin: 0;
}
.image-figure {
margin-right: 100px;
text-align: center;
}
.image-figure img {
height: 500px;
width: 500px;
}
.table {
width: 100%;
font-size: 20px;
}
.table td {
height: 100px;
width: 500px;
}
.table figure {
position: relative;
height: 150px;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
}
.table img {
height: 100px;
margin: 0;
top: 0;
background: transparent;
}
.table figcaption {
text-align: center;
font-size: 27px;
width: 100%;
bottom: 0;
}
</style>
$$
\begin{array}{c}
\texttt{C++ Competitive Programming Course}\\
\textbf{Introduction to Competitive Programming}\\
\end{array}
$$
<table style="font-size: 27px;">
<tr>
<td class="green"><strong>Lecturer:</strong></td>
<td class="orange">Võ Hoàng Anh</td>
<td class="green"><strong>Course:</strong></td>
<td class="orange">9CTIN</td>
</tr>
<tr>
<td class="green"><strong>Nickname:</strong></td>
<td class="orange">@SPyofgame</td>
<td class="green"><strong>Semester:</strong></td>
<td class="orange">2024-2025</td>
</tr>
<tr>
<td class="green"><strong>Assistant:</strong></td>
<td class="orange">Lâm Quang Phú</td>
<td class="green"><strong>Session:</strong></td>
<td class="orange">#3</td>
</tr>
</table>
<table style="font-size: 20px;">
<tr>
<td colspan="4" class="red"><strong>Course Info:</strong> </td>
<td> <a href="https://hackmd.io/@staredu/index">https://hackmd.io/@staredu/index</a></td>
</tr>
<tr>
<td colspan="4" class="red"><strong>Read as note:</strong> </td>
<td> <a href="https://hackmd.io/@staredu/beginning">https://hackmd.io/@staredu/beginning</a></td>
</tr>
<tr>
<td colspan="4" class="red"><strong>Read as slide:</strong> </td>
<td> <a href="https://hackmd.io/@staredu/slide3">https://hackmd.io/@staredu/slide3</a></td>
</tr>
<tr>
<td colspan="4" class="red"><strong>Hashed link:</strong> </td>
<td> <a href="https://hackmd.io/f2u22jyvQPK-NyBZV8WsRA?view#/">https://hackmd.io/f2u22jyvQPK-NyBZV8WsRA?view#/</a></td>
</tr>
</table>
---
## IV - Table of content
```yml=
[IV.1 - Basic knowledge] [IV.2 - Constants & Types]
-> Block of commands -> Primitive types
-> Algorithm & Data-Structure -> Range of values
-> Syntax & Keyword -> Initialization
-> Include and Library -> Macro vs Const
-> C & C++ relationship -> Expression
[IV.3 - Variables & Types] [IV.4 - More about Type]
-> Variable vs Const -> Type aliases
-> Arithmetic -> Auto
-> L-value & R-value -> Binding
-> Unsigned vs Signed -> Literal
-> Evaluation Order -> Enum (named values)
```
---
### IV.1 - Basics knowledge
```yml=
[1-a) Block of commands] [1-b) Algorithm & Data-Structure]
-> Statements -> Simplified task
-> Statement Block -> State machine
-> Main Function -> Practical problem
[1-c) Syntax & Keyword] [1-d) Include and Library]
-> Expression -> #include <...>
-> Identifiers -> #include <bits/stdc++.h>
-> Flow control -> #include "..."
[1-e) C & C++ relationship] [1-f) Others]
-> Historical -> Frequently Asked Questions
-> Compatibility -> Review
-> Competitive Programming -> Sidenote
```
---
#### IV.1-a) Block of commands
<center>
<table class="table">
<tr>
<td>
<figure>
<img src="https://hackmd.io/_uploads/HJc9FWHLR.png" alt="">
<figcaption>i) Statement</figcaption>
</figure>
</td>
<td>
<figure>
<img src="https://hackmd.io/_uploads/H11bcWBL0.png" alt="">
<figcaption>ii) Statement Block</figcaption>
</figure>
</td>
<td>
<figure>
<img src="https://hackmd.io/_uploads/SJh-qWBIR.png" alt="">
<figcaption>iii) Main Function</figcaption>
</figure>
</td>
</tr>
<tr>
<td>
<figure>
<img src="https://hackmd.io/_uploads/HyX5tGBI0.png" alt="">
<figcaption>iv) Example of (i)</figcaption>
</figure>
</td>
<td>
<figure>
<img src="https://hackmd.io/_uploads/rJKxtzBLR.png" alt="">
<figcaption>v) Example of (ii)</figcaption>
</figure>
</td>
<td>
<figure>
<img src="https://hackmd.io/_uploads/B1HZKzBLC.png" alt="">
<figcaption>vi) Example of (iii)</figcaption>
</figure>
</td>
</tr>
</table>
</center>
----
#### IV.1-a) Block of commands
##### IV.1-a:i) Statement
> `What is a computer statement ?`
> A computer program is a sequence of instructions that tell the computer what to do.
> `What does a statement do ?`
> A statement is a type of instruction that causes the program to perform some actions.
> `What is a C++ statement ?`
> Statements are by far the most common type of instruction in a C++ program.
> This is because they are the smallest independent unit of computation in C++.
> A single statement may compile into many machine language instructions (depend on enviroments).
> `Statement act like natural-language sentence !`
> To convey an idea to another person, we typically write or speak in sentences.
> In C++, when we want to have our program do something, we typically write statements.
> Most statements in C++ end in a semicolon <code>;</code>.
----
#### IV.1-a) Block of commands
##### IV.1-a:ii) Statement Block
> `What is a statement block ?`
> A statement block in C++ groups multiple statements within curly braces `{}`.
> A block is a single compound statement that allows multiple operations to be executed sequentially.
> `What does a statement block do ?`
> A statement block organizes related statements into a collective unit, which is particularly useful in controlling the flow of execution in programs, especially loops, conditionals, and function definitions.
> `What is a C++ statement block ?`
> In C++, a statement block is a compound statement enclosed in curly braces. It can contain declarations, expressions, and other statement blocks, making it a versatile tool for structuring complex logic.
> `Statement block acts like a paragraph in natural-language!`
> Just as a paragraph groups related sentences to form a complete idea, a statement block groups related statements to execute a sequence of operations. This structure is critical for maintaining clean, readable, and organized code in larger programs. For example, this explanation itself is also a paragraph.
----
#### IV.1-a) Block of commands
##### IV.1-a:iii) Main function
> `What is the main function in C++ ?`
> Every C++ program have a special function named `main` (all lower case letters)
> It's where the execution of the program begins by default of most IDE.
> Depending on its design, it directs the program flow by calling other functions and managing data.
> `Where does execution start ?`
> Execution starts with the first statement inside the main function.
> `Code termination ?`
> Programs typically terminate (finish running) after the last statement inside function main has been executed (though programs may abort early in some circumstances, or do some cleanup afterwards).
> `Advanced ?`
> You can abuse `#define` or `asm` to make things ambiguity and break common sense.
> But for most of the cases, you might not want to do that, nor required to learn how.
> The few exceptions are april fools codeforces round, amusement tricks, or special ad-hocs.
----
#### IV.1-a) Block of commands
##### IV.1-a:iv) Statement Example
> `Common example`
> ```cpp
> int value; // Declaration statement
> int x = 5; // Declaration statement with initialization
> x = x * 2; // Expression statement
> value = x; // Assignment statement
> std::cout << value; // Output statement
> ```
> `Explaination ?`
> ```cpp
> int value; // Make a variable named "value"
> int x = 5; // Make a variable named "x" and init it with value "5"
> x = x * 2; // Double the value of "x", from "5" to "10" (since 5 * 2 = 10)
> value = x; // Assign the value of "value" to be the same as "x" ( = "10")
> std::cout << value; // Output "value" from output-stream named "std::cout"
> ```
----
#### IV.1-a) Block of commands
##### IV.1-a:v) Statement Example
> `Example`
> The curly braces `{...}` define the boundaries of the statements `...` inside the block.
> ```cpp
> { // Begin block of statements
> int x = 10; // Declaration and initialization of a local variable
> int y = 20;
> int sum = x + y; // Perform an operation and store the result
> std::cout << "Sum of x and y is " << sum; // Output the result
> } // End block of statements
> ```
> `Execution ?`
> All statements within the block are executed in sequence.
> This example initializes two integers, calculates their sum, and then outputs the result.
> `Usage ?`
> This type of block is useful when you want to isolate a part of the program into a block.
> This ensures that multiple statements are seen as a conceptual unit without concerning others.
> `Advanced`
> They are created when the block is entered and destroyed when it is exited.
> Variables declared within these braces, such as `x`, `y`, and `sum`, are local to the block.
----
#### IV.1-a) Block of commands
##### IV.1-a:vi) Main function
> `Simple example`
> ```cpp
> #include /* library */
> int main() {
> std::cout << "Hello World!"; // output this string to the terminal
> return 0; // main() return int(0) indicate the code run successfully
> }
> ```
> `Full format`
> ```cpp
> int main(int argc, char* argv[], char* envp[]) { ... }
> // ^ ^ ^ ^
> // | | | |
> // | | | code inside it
> // | | |
> // | | enviroment variable, ex:
> // | |
> // | command-line argument, ex:
> // |
> // number of arguments
> ```
---
---
#### IV.1-b) Algorithm & Data-Structure
----
#### IV.1-b) Algorithm & Data-Structure
##### IV.1-b:i) Simplified Task
> `Why do we break complex problems into simpler ones?`
> Breaking down complex problems into simpler parts makes them easier to understand and solve.
> Just like solving a big puzzle is easier when you sort it into smaller sections, tackling a big programming problem piece by piece helps you solve it more efficiently, you can then combine them back later.
> This approach also helps identify and isolate errors more quickly, as you can test each part separately.
> `Why do we solve abstract problems?`
> Solving abstract problems helps us develop solutions that can be applied to a range of similar problems, not just one specific case. This means once you solve the abstract problem, you can use that solution for many different situations. It’s like learning how to navigate a city map; once you understand the layout, you can apply that knowledge to find your way around any part of the city.
> `Give me an example of a practical problem that is commonly abstracted?`
> A common example of abstracting a practical problem in programming is creating a sorting function. Sorting is a fundamental task in programming used in various applications like find top 10 students (based on GPA), organizing files, processing data, or even ranking players in a game. By developing a general sorting function, you can reuse it in any of these scenarios without having to rewrite new code each time. This not only saves time but also reduces errors and improves the quality of your programs.
----
#### IV.1-b) Algorithm & Data-Structure
##### IV.1-b:ii) State Machine
> `What is a state machine in C++?`
> A state machine is a conceptual model used to design systems that can be in one of a number of different states. Depending on input or other changes, the system transitions from one state to another.
> `What does a state machine do?`
> State machines are used to manage complex conditions and behaviors in software, especially where the system has to react differently depending on inputs or events.
> `Example of a state machine in C++`
> ```cpp
> enum State { START, STOP, PAUSE, PLAY };
> State currentState = START;
> void updateState(char command) {
> switch (command) {
> case 'P': currentState = PLAY; break;
> case 'p': currentState = PAUSE; break;
> case 's': currentState = STOP; break;
> default: currentState = START;
> }
> }
> ```
> `Explanation`
> This code defines an enumeration `State` with four possible states. The `updateState` function adjusts the current state based on a character input, demonstrating a simple state machine where transitions are controlled by user input.
----
#### IV.1-b) Algorithm & Data-Structure
##### IV.1-b:iii) Practical Problem
> `What is a practical problem in C++?`
> Practical problems in programming are real-world challenges that require algorithmic solutions, like data analysis, automation tasks, or user interaction handling.
> `What does solving a practical problem involve?`
> Solving a practical problem involves applying algorithms and data structures to implement effective and efficient solutions that meet user needs or system requirements.
> `Example of solving a practical problem in C++`
> ```cpp
> int factorial(int n) {
> if (n <= 1) return 1;
> else return n * factorial(n - 1);
> }
> ```
> `Explanation`
> This function calculates the factorial of a number using recursion, a common method for solving problems that can be broken down into simpler, repetitive tasks. This is a practical implementation of a mathematical problem in programming.
This format helps in organizing and explaining C++ concepts related to algorithms and data structures by breaking them down into basic tasks, state machine models, and practical problem-solving techniques, providing both definitions and examples for clearer understanding.
---
### IIV - Syntax & Keyword
---
### II.4 - Implementation
---
### II.5 - C & C++ relationship
---
## III. Constants & Types
```yml=
[III.1 - Primitive types] [III.2 - Range of values]
-> Integer types -> Character
-> Floating-point types -> Integer
-> Void and std::nullptr_t -> Floating-point
[IIIV - Initialization] [III.4 - Macro vs Const]
-> Single -> #define, #undef
-> Multiple -> const optimization
-> Based on others -> naming pollution
[III.5 - Expression] [III.6 - Others]
-> Basic Arithmetics -> Frequently Asked Questions
-> Expression -> Review
-> Evaluation order -> Sidenote
```
---
### III.1 - Primitive types
- int, short int, long int, long long int
- float, double, long double
-
---
### III.2 - Range of values
---
### IIIV - Initialization
---
### III.4 - Macro vs Const
---
### III.5 - Expressions
---
## IV. Variables
```yml=
[IV.1 - Variable vs Const] [IV.2 - Arithmetic]
-> What is a variable ? -> Assignments
-> When do we use variables ? -> Incremenets & Decrements
-> -> References
[IV.3 - L-value & R-value] [IV.4 - Unsigned vs Signed]
-> ->
-> ->
-> ->
[IV.5 - Evaluation Order] [IV.6 - FAQ]
-> -> Frequently Asked Questions
-> -> Review
-> -> Sidenote
```
---
### IV.1 - Variable vs Const
---
### IV.2 - Aliases & Typedef
---
### IV.3 - L-value & R-value
---
### IV.4 - Unsigned vs Signed
---
### IV.5 - Evaluation Order
---
## V. More about Types
```yml=
[V.1 - Type aliases] [V.2 - Auto]
-> typedef ->
-> using ->
-> #define ->
[V.3 - Binding] [V.4 - Literal]
-> ->
-> ->
-> ->
[V.5 - Enum] [V.6 - Others]
-> -> Frequently Asked Questions
-> -> Review
-> -> Sidenote
```
---
### V.1 - Type Cast
---
### V.2 - Auto
---
### V.3 - Binding
---
### V.4 - Literal
---
### V.5 - Enum
---
## VI. Remarks
---
### VI.1 - Facts
---
#### VI.1-a) How much effort did you spend ?
- I spent 5 days straight just to make these slides.
- I verified everything lines by lines.
---
#### VI.1-b) Why this slide is long as fuck ?
- You will forget most of them anyways.
- You can review this any time.
- There are things people find it obvious.
- There are misconceptions among people.
---
#### VI.1-c) Why do you use English ?
- I will make Vietnamese translation soon.
- English Keywords provide more resources.
{"title":"Star Edu, Slide 4","description":"int, short int, long int, long long int","contributors":"[{\"id\":\"a22ea847-846d-438a-bc33-27664a818ea5\",\"add\":29742,\"del\":10025}]"}