In C++, the function atoi() is designed to convert characters to integers. If a character is named n, all that is needed to convert it to an integer is: In other words, the atoi function wraps around the character and changes it to an integer.
C++
Initial Value
Initial value for variables is very important in C++. If a variable is in the wrong scope, errors can appear, or it won’t give the expected outcome. For example, if a variable is declared in a for loop, and it is used in a function, the announced variable will not…
CCC ’18 J4 (S2)
Matrices are among an important group in coding problems. Matrix rotations are also vital. For instance, QR codes can be read even when it is rotated 90°. Take the coding problem below as an example: https://dmoj.ca/problem/ccc18s2 This is a matrix problem. At first glance, people might thnk that the data…
Value Scope
In C++, value scope is important for declaring variables. If a variable is declared in a for loop, it is different than if it is announced in the main() function. If the variable is declared in the for loop, it will only be present in the loop. In the main()…
Test For No Errors!
Remember: in C++, a frequent thing that needs to be done is to test (use debugging code) to check that there are no mistakes. Why? Mistakes could be solved easily, but if there are too many all of them would be hard to solve. Plus, if an entire program was…
C++ stoi()
In C++, the stoi() function is useful to change strings to integers. Basically, it only needs one parameter, and it is like stoi(something). Example: Example Output: And that’s all! In short, stoi() is a function that converts strings into integers.
CCC ’21 J4 – Solution
Arranging Books is a coding problem that can be viewed here. It isn’t easy, and is literally impossible to solve it correctly by actually swapping books. Here is the problem: Canadian Computing Competition: 2021 Stage 1, Junior #4 Valentina wants books on a shelf to be arranged in a particular…
C++ substr()
In C++, the substr() method is one of the easiest functions to use to split a string into multiple slices. Here are the parameters of the substr(): where name is the string that you want to be sliced, position is the staring point, and len is the number of characters…
