SlideShare a Scribd company logo
1 of 31
Download to read offline
ACM Aleppo CPC Training
Part 1 C++ Programming Concepts
By Ahmad Bashar Eter
C++ Review
Variables & Data types
• To define a variable: [TypeName] [VariableName];
• Integer data types:
Note: int data type is 2 byte signed on some compilers and 4 on other.
Type name Size Range
char 1 byte signed -128 to 127
unsigned char 1 byte unsigned 0 to 255
short 2 byte signed -32,768 to 32,767
unsigned short 2 byte unsigned 0 to 65,535
long 4 byte signed -2,147,483,648 to 2,147,483,647
unsigned long 4 byte unsigned 0 to 4,294,967,295
long long 8 byte signed
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
unsigned long long 8 byte unsigned 0 to 18,446,744,073,709,551,615
Variables & Data types
• char type is also used to represent alphabets.
• Floating point data types (Real values):
• Boolean data type (true or false state variable): bool its size is 1 byte.
Type name Size Range Precision
float 4 bytes ±1.18 x 10-38 to ±3.4 x 1038 6-9 significant digits, typically 7
double 8 bytes ±2.23 x 10-308 to ±1.80 x 10308 15-18 significant digits, typically 16
Flow control statements
• If statement.
• Switch statement.
• While loop statement.
• For loop statement.
• Break and continue.
Flow control: if statement
• Syntax: If (Conditional expression)
one expression or {expressions block}
else if (Conditional expression)
one expression or {expressions block}
else if (Conditional expression)
one expression or {expressions block}
.
.
.
else if (Conditional expression)
one expression or {expressions block}
else
one expression or {expressions block}
Flow control: switch statement
• Syntax: switch(integer expression)
{
case (case value):
[break];
case (case value):
[break];
case (case value):
[break];
default:
[break];
}
Flow control: switch statement
• Used over if statement if we have a lot of equal condition if
statement (it is much faster than if statement).
• Note: we can leave out the brake statement if we want some cases
to do the same statements.
Flow control: while loop statement
• Syntax: while (Conditional expression)
one expression or {expressions block}
• Anther form: do
one expression or {expressions block}
while (Conditional expression)
• Used when we don’t know how many times we will loop.
• Note: we can use it to do infant loop if the condition will never be
false (ex. 10>0 , true).
Flow control: for loop statement
• Syntax
for(loop initialization; loop condition; increment expression)
one expression or {expressions block}
• Used when we know exactly how many times we will loop.
• We can omit the loop initialization , loop condition or increment
expression if we want to.
• Note: we can use it to do infant loop if the loop condition will never
be false (ex. 10>0 , true) or if we leave out the loop condition .
Flow control: break & continue
• If we want to skip the running iteration of the loop, we can use the
continue statement.
• If we want to terminate all the work of the loop, we can use the
break statement.
IO methods
• In C++ if we want to output something on the screen, we can use
cout stream.
• If we want to get an input from what the user is typing on the
screen, we can use cin stream.
• In general, cin cout streams are slow in programing contests.
• To get faster IO methods you may use the C programing language
methods printf and scanf.
• Or you may put this statement before any cin or cout statement:
ios::sync_with_stdio (false);
• This statement turns off the synchronization between the C++ IO
and C IO, so once you use it you can’t use printf and scanf.
IO techniques
• If we have many number of test cases or you don’t know how many
test cases you will get and you want to read the test cases while
there is a test case to read (or until you reach the end of the file)
you can use this statement which read x while the input file still
have x in it: while(cin >> x)
• If we don’t know how many test cases but we know that the file end
with zero we may use this statement: while(cin >> x && x)
• If we know how many test cases we can put the number of test
cases in for loop.
Example 1: A. Choosing Teams
The Saratov State University Olympiad Programmers Training Center (SSU
OPTC) has n students. For each student you know the number of times
he/she has participated in the ACM ICPC world programming
championship. According to the ACM ICPC rules, each person can
participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in
the world championship. Each team must consist of exactly three
people, at that, any person cannot be a member of two or more teams.
What maximum number of teams can the head make if he wants each
team to participate in the world championship with the same members
at least k times?
Solve at:
Example 1: A. Choosing Teams
Input:
The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The
next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the
number of times the i-th person participated in the ACM ICPC world
championship.
Output:
Print a single number — the answer to the problem.
Solve at:
Example 1: A. Choosing Teams
1. #include <iostream>
2. using namespace std;
3. int main() {
4. ios::sync_with_stdio(false);
5. int teamscount = 0, invidualcount = 0, n, k, x;
6. cin >> n >> k;
7. for (int i = 0; i < n; i++) {
8. cin >> x;
9. if (k + x <= 5) {
10. invidualcount++;
11. if (invidualcount == 3) {
12. invidualcount = 0;
13. teamscount++;
14. }
15. }
16. }
17. cout << teamscount << endl;
18. return 0;
19.}
Solve at:
Example 2: B. Present from Lena
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a
present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The
largest digit n should be located in the centre. The digits should decrease as they approach
the edges. For example, for n = 5 the handkerchief pattern should look like that:
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 3 4 3 2 1 0
0 1 2 3 4 5 4 3 2 1 0
0 1 2 3 4 3 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0
Solve at:
Example 2: B. Present from Lena
Your task is to determine the way the handkerchief will look like by the
given n.
Input
The first line contains the single integer n (2 ≤ n ≤ 9).
Output
Print a picture for the given n. You should strictly observe the number of
spaces before the first digit on each line. Every two adjacent digits in the
same line should be separated by exactly one space. There should be no
spaces after the last digit at the end of each line.
Solve at:
Example 2: B. Present from Lena
1. #include <iostream>
2. using namespace std;
3. int main() {
4. ios::sync_with_stdio(false);
5. int n;
6. cin >> n;
7. for (int i = 0; i < 2*n + 1; i++){
8. int charcters = n;
9. if (n - i > 0)
10. charcters -= n - i;
11. else
12. charcters -= i - n;
13. int spaces = 2 * n + 1 - ( 2 *
charcters + 1);
Solve at:
14. for (int j = 0;j < spaces/2; j++){
15. cout << " ";
16. }
17. for (int j = 0;j < charcters;j++){
18. cout << j << " ";
19. }
20. for (int j =charcters;j >=0; j--){
21. cout << j;
22. if (j)
23. cout << " ";
24. }
25. cout << endl;
26. }
27. return 0;
28.}
IO techniques
• If we want to output new line between each two test cases we can
put endl at the end of each test case but if we don’t want to put
endl at the end we have one of this choices:
1. We can put if statement at the end of the test case to check if this
is not the last test case:
if(t < T-1) cout << endl; // Where T: Number of Test cases
2. If we don’t know the number of test cases we my put if statement
at the beginning of each one to assert if it is not the first one so
we must put a new line to separate it from the last test case:
if(t) cout << endl; // Where t: 0-based index of the current test
case
Arrays:
To define array in C++: array_type array_name[number of elements]
• Note that the number of element in this type of array must be
constant.
• To define a constant value you may use the key word const before
the variable declaration.
• Usually we define the big arrays (have more than 1 KB) in global
scope to avoid stack overflow.
• Usually we define the array to have a constant element size big
enough to have the maximum number of element that the user may
input and then use how many we want from it.
Arrays:
• In C++ there is an operator called sizeof() used to get the size of a
fixed size identifier (variable array pointer….) in bytes we can use it
to determine the size of the array in bytes.
• Also in the cstring library we have a function called memset which
take 3 parameters 1- the destination, 2- the values ,3- the size of the
destination.
• This function can be used to fill an array with zeros to initialize it
before we can use it:
int a[10000];
memset(a,0,sizeof(a));
Arrays:
• Arrays can be used in too many points in code to store block of
code to process (reveres, sort, transform…..) or to extract distinct
elements of input and a lot more….
Strings:
• Strings is a type that represent array of characters.
• There is two type of strings we can use:
1. The C style string which is a char array and we will not use it for
now.
2. The C++ style string which is an object of the class string exist in
the <string> library. We will use it or now cause it is much easier.
• We can define a string the same way we define any variable but first
of all we must include the string library.
• We can access any character in the string by its index like if the
string is a 0-based index char array.
Strings:
• We will talk a lot more on strings in the next lechers but for now we
will take a lot of examples.
Example 3: Minesweeper
Have you ever played Minesweeper? It’s a cute little game which comes within a certain
Operating System which name we can’t really remember. Well, the goal of the game is to find
where are all the mines within a M × N field. To help you, the game shows a number in a
square which tells you how many mines there are adjacent to that square. For instance,
supose the following 4 × 4 field with 2 mines (which are represented by an ‘*’ character):
*...
....
.*..
....
If we would represent the same field placing the hint numbers described above, we would
end up with:
*100
2210
1*10
1110
have already noticed, each square may have at most 8 adjacent squares
Solve at:
Example 3: Minesweeper
Input:
The input will consist of an arbitrary number of fields. The first line of each
field contains two integers n and m (0 < n, m ≤ 100) which stands for the
number of lines and columns of the field respectively. The next n lines contains
exactly m characters and represent the field. Each safe square is represented by
an ‘.’ character (without the quotes) and each mine square is represented by an
‘*’ character (also without the quotes). The first field line where n = m = 0
represents the end of input and should not be processed.
Output:
For each field, you must print the following message in a line alone: Field #x:
Where x stands for the number of the field (starting from 1). The next n lines
should contain the field with the ‘.’ characters replaced by the number of
adjacent mines to that square. There must be an empty line between field
outputs.
Solve at:
Example 4: Cakeminator
You are given a rectangular cake, represented as an r × c grid. Each cell
either has an evil strawberry, or is empty. For example, a 3 × 4 cake may
look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a
row or a column that does not contain any evil strawberries and contains
at least one cake cell that has not been
eaten before, and eats all the cake cells there.
He may decide to eat any number of times.
Please output the maximum number of cake
cells that the cakeminator can eat.
Solve at:
Example 4: Cakeminator
Input:
The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the
number of rows and the number of columns of the cake. The next r lines
each contains c characters — the j-th character of the i-th line denotes
the content of the cell at row i and column j, and is either one of these:
'.' character denotes a cake cell with no evil strawberry;
'S' character denotes a cake cell with an evil strawberry.
Output:
Output the maximum number of cake cells that the cakeminator can eat.
Solve at:
Other Exercises
Try these good exercises and remember the more you exercise, the
better you will become ;).
• Codeforces A. Boy or Girl
• Codeforces A. Presents
• Codeforces B. Permutation
Thank you :) :) :)

More Related Content

What's hot

Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVS
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVSCBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVS
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVSGautham Rajesh
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional StatementsIntro C# Book
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output Intro C# Book
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01Md. Ashikur Rahman
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambalajatin batra
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : PythonRaghu Kumar
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotesSowri Rajan
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++Manzoor ALam
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Ali Aminian
 

What's hot (20)

Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C string
C stringC string
C string
 
Python ppt
Python pptPython ppt
Python ppt
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVS
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVSCBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVS
CBSE XII COMPUTER SCIENCE STUDY MATERIAL BY KVS
 
14 strings
14 strings14 strings
14 strings
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional Statements
 
C++ theory
C++ theoryC++ theory
C++ theory
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
 
C# Strings
C# StringsC# Strings
C# Strings
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala
 
Strings
StringsStrings
Strings
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
 
Modern C++
Modern C++Modern C++
Modern C++
 

Similar to Acm aleppo cpc training second session

LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfSHASHIKANT346021
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfShashikantSathe3
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
primitive data types
 primitive data types primitive data types
primitive data typesJadavsejal
 
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdfdhruvjs
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
C++ Loops General Discussion of Loops A loop is a.docx
C++ Loops  General Discussion of Loops A loop is a.docxC++ Loops  General Discussion of Loops A loop is a.docx
C++ Loops General Discussion of Loops A loop is a.docxhumphrieskalyn
 
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH  SRIVATHS PC_BASICS FOR C PROGRAMMER WITH  SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH SRIVATHS Pamankr1234am
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
Basics of Python
Basics of PythonBasics of Python
Basics of PythonEase3
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing TutorialMahira Banu
 

Similar to Acm aleppo cpc training second session (20)

LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
primitive data types
 primitive data types primitive data types
primitive data types
 
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
C++ Loops General Discussion of Loops A loop is a.docx
C++ Loops  General Discussion of Loops A loop is a.docxC++ Loops  General Discussion of Loops A loop is a.docx
C++ Loops General Discussion of Loops A loop is a.docx
 
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH  SRIVATHS PC_BASICS FOR C PROGRAMMER WITH  SRIVATHS P
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 

Acm aleppo cpc training second session

  • 1. ACM Aleppo CPC Training Part 1 C++ Programming Concepts By Ahmad Bashar Eter
  • 3. Variables & Data types • To define a variable: [TypeName] [VariableName]; • Integer data types: Note: int data type is 2 byte signed on some compilers and 4 on other. Type name Size Range char 1 byte signed -128 to 127 unsigned char 1 byte unsigned 0 to 255 short 2 byte signed -32,768 to 32,767 unsigned short 2 byte unsigned 0 to 65,535 long 4 byte signed -2,147,483,648 to 2,147,483,647 unsigned long 4 byte unsigned 0 to 4,294,967,295 long long 8 byte signed -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned long long 8 byte unsigned 0 to 18,446,744,073,709,551,615
  • 4. Variables & Data types • char type is also used to represent alphabets. • Floating point data types (Real values): • Boolean data type (true or false state variable): bool its size is 1 byte. Type name Size Range Precision float 4 bytes ±1.18 x 10-38 to ±3.4 x 1038 6-9 significant digits, typically 7 double 8 bytes ±2.23 x 10-308 to ±1.80 x 10308 15-18 significant digits, typically 16
  • 5. Flow control statements • If statement. • Switch statement. • While loop statement. • For loop statement. • Break and continue.
  • 6. Flow control: if statement • Syntax: If (Conditional expression) one expression or {expressions block} else if (Conditional expression) one expression or {expressions block} else if (Conditional expression) one expression or {expressions block} . . . else if (Conditional expression) one expression or {expressions block} else one expression or {expressions block}
  • 7. Flow control: switch statement • Syntax: switch(integer expression) { case (case value): [break]; case (case value): [break]; case (case value): [break]; default: [break]; }
  • 8. Flow control: switch statement • Used over if statement if we have a lot of equal condition if statement (it is much faster than if statement). • Note: we can leave out the brake statement if we want some cases to do the same statements.
  • 9. Flow control: while loop statement • Syntax: while (Conditional expression) one expression or {expressions block} • Anther form: do one expression or {expressions block} while (Conditional expression) • Used when we don’t know how many times we will loop. • Note: we can use it to do infant loop if the condition will never be false (ex. 10>0 , true).
  • 10. Flow control: for loop statement • Syntax for(loop initialization; loop condition; increment expression) one expression or {expressions block} • Used when we know exactly how many times we will loop. • We can omit the loop initialization , loop condition or increment expression if we want to. • Note: we can use it to do infant loop if the loop condition will never be false (ex. 10>0 , true) or if we leave out the loop condition .
  • 11. Flow control: break & continue • If we want to skip the running iteration of the loop, we can use the continue statement. • If we want to terminate all the work of the loop, we can use the break statement.
  • 12. IO methods • In C++ if we want to output something on the screen, we can use cout stream. • If we want to get an input from what the user is typing on the screen, we can use cin stream. • In general, cin cout streams are slow in programing contests. • To get faster IO methods you may use the C programing language methods printf and scanf. • Or you may put this statement before any cin or cout statement: ios::sync_with_stdio (false); • This statement turns off the synchronization between the C++ IO and C IO, so once you use it you can’t use printf and scanf.
  • 13. IO techniques • If we have many number of test cases or you don’t know how many test cases you will get and you want to read the test cases while there is a test case to read (or until you reach the end of the file) you can use this statement which read x while the input file still have x in it: while(cin >> x) • If we don’t know how many test cases but we know that the file end with zero we may use this statement: while(cin >> x && x) • If we know how many test cases we can put the number of test cases in for loop.
  • 14. Example 1: A. Choosing Teams The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times? Solve at:
  • 15. Example 1: A. Choosing Teams Input: The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship. Output: Print a single number — the answer to the problem. Solve at:
  • 16. Example 1: A. Choosing Teams 1. #include <iostream> 2. using namespace std; 3. int main() { 4. ios::sync_with_stdio(false); 5. int teamscount = 0, invidualcount = 0, n, k, x; 6. cin >> n >> k; 7. for (int i = 0; i < n; i++) { 8. cin >> x; 9. if (k + x <= 5) { 10. invidualcount++; 11. if (invidualcount == 3) { 12. invidualcount = 0; 13. teamscount++; 14. } 15. } 16. } 17. cout << teamscount << endl; 18. return 0; 19.} Solve at:
  • 17. Example 2: B. Present from Lena Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that: 0 0 1 0 0 1 2 1 0 0 1 2 3 2 1 0 0 1 2 3 4 3 2 1 0 0 1 2 3 4 5 4 3 2 1 0 0 1 2 3 4 3 2 1 0 0 1 2 3 2 1 0 0 1 2 1 0 0 1 0 0 Solve at:
  • 18. Example 2: B. Present from Lena Your task is to determine the way the handkerchief will look like by the given n. Input The first line contains the single integer n (2 ≤ n ≤ 9). Output Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line. Solve at:
  • 19. Example 2: B. Present from Lena 1. #include <iostream> 2. using namespace std; 3. int main() { 4. ios::sync_with_stdio(false); 5. int n; 6. cin >> n; 7. for (int i = 0; i < 2*n + 1; i++){ 8. int charcters = n; 9. if (n - i > 0) 10. charcters -= n - i; 11. else 12. charcters -= i - n; 13. int spaces = 2 * n + 1 - ( 2 * charcters + 1); Solve at: 14. for (int j = 0;j < spaces/2; j++){ 15. cout << " "; 16. } 17. for (int j = 0;j < charcters;j++){ 18. cout << j << " "; 19. } 20. for (int j =charcters;j >=0; j--){ 21. cout << j; 22. if (j) 23. cout << " "; 24. } 25. cout << endl; 26. } 27. return 0; 28.}
  • 20. IO techniques • If we want to output new line between each two test cases we can put endl at the end of each test case but if we don’t want to put endl at the end we have one of this choices: 1. We can put if statement at the end of the test case to check if this is not the last test case: if(t < T-1) cout << endl; // Where T: Number of Test cases 2. If we don’t know the number of test cases we my put if statement at the beginning of each one to assert if it is not the first one so we must put a new line to separate it from the last test case: if(t) cout << endl; // Where t: 0-based index of the current test case
  • 21. Arrays: To define array in C++: array_type array_name[number of elements] • Note that the number of element in this type of array must be constant. • To define a constant value you may use the key word const before the variable declaration. • Usually we define the big arrays (have more than 1 KB) in global scope to avoid stack overflow. • Usually we define the array to have a constant element size big enough to have the maximum number of element that the user may input and then use how many we want from it.
  • 22. Arrays: • In C++ there is an operator called sizeof() used to get the size of a fixed size identifier (variable array pointer….) in bytes we can use it to determine the size of the array in bytes. • Also in the cstring library we have a function called memset which take 3 parameters 1- the destination, 2- the values ,3- the size of the destination. • This function can be used to fill an array with zeros to initialize it before we can use it: int a[10000]; memset(a,0,sizeof(a));
  • 23. Arrays: • Arrays can be used in too many points in code to store block of code to process (reveres, sort, transform…..) or to extract distinct elements of input and a lot more….
  • 24. Strings: • Strings is a type that represent array of characters. • There is two type of strings we can use: 1. The C style string which is a char array and we will not use it for now. 2. The C++ style string which is an object of the class string exist in the <string> library. We will use it or now cause it is much easier. • We can define a string the same way we define any variable but first of all we must include the string library. • We can access any character in the string by its index like if the string is a 0-based index char array.
  • 25. Strings: • We will talk a lot more on strings in the next lechers but for now we will take a lot of examples.
  • 26. Example 3: Minesweeper Have you ever played Minesweeper? It’s a cute little game which comes within a certain Operating System which name we can’t really remember. Well, the goal of the game is to find where are all the mines within a M × N field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, supose the following 4 × 4 field with 2 mines (which are represented by an ‘*’ character): *... .... .*.. .... If we would represent the same field placing the hint numbers described above, we would end up with: *100 2210 1*10 1110 have already noticed, each square may have at most 8 adjacent squares Solve at:
  • 27. Example 3: Minesweeper Input: The input will consist of an arbitrary number of fields. The first line of each field contains two integers n and m (0 < n, m ≤ 100) which stands for the number of lines and columns of the field respectively. The next n lines contains exactly m characters and represent the field. Each safe square is represented by an ‘.’ character (without the quotes) and each mine square is represented by an ‘*’ character (also without the quotes). The first field line where n = m = 0 represents the end of input and should not be processed. Output: For each field, you must print the following message in a line alone: Field #x: Where x stands for the number of the field (starting from 1). The next n lines should contain the field with the ‘.’ characters replaced by the number of adjacent mines to that square. There must be an empty line between field outputs. Solve at:
  • 28. Example 4: Cakeminator You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Solve at:
  • 29. Example 4: Cakeminator Input: The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these: '.' character denotes a cake cell with no evil strawberry; 'S' character denotes a cake cell with an evil strawberry. Output: Output the maximum number of cake cells that the cakeminator can eat. Solve at:
  • 30. Other Exercises Try these good exercises and remember the more you exercise, the better you will become ;). • Codeforces A. Boy or Girl • Codeforces A. Presents • Codeforces B. Permutation
  • 31. Thank you :) :) :)