SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
ACM Aleppo CPC Training
Part 1 C++ Programming Concepts
By Ahmad Bashar Eter
Reminder
This is the most used containers:
vector : dynamic array
list : linked list data structure
set : a sorted binary search tree
map : associated container a sorted binary search tree
unordedset : hash table
unordedmap : associated container hash table
queue : queue data structure
stack : stack data structure
priority queue : max heap data structure
Reference:
Example 1: Array
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into
three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero ( < 0).
2. The product of all numbers in the second set is greater than zero ( > 0).
3. The product of all numbers in the third set is equal to zero.
Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Solve At:
Example 1: Array
Input: The first line of the input contains integer n (3 ≤ n ≤ 100). The second line
contains n space-separated distinct integers a1, a2, ..., an(|ai| ≤ 103) — the array
elements.
Output: In the first line print integer n1 (n1 > 0) — the number of elements in the
first set. Then print n1 numbers — the elements that got to the first set.
In the next line print integer n2 (n2 > 0) — the number of elements in the second
set. Then print n2 numbers — the elements that got to the second set.
In the next line print integer n3 (n3 > 0) — the number of elements in the third
set. Then print n3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the
solution exists. If there are several solutions, you are allowed to print any of
them.
Solve At:
Example 1: Array
Sample Input
3
-1 2 0
Solve At:
Sample Output
1 -1
1 2
1 0
Some STL Algorithms
• We have seen so far how to sort data in ascending order we.
• Some time we need to sort data in special way, in order to
customize our sort algorithm we can give the sort algorithm a
predict function that tell the algorithm if two element are in the
right order or not.
• This function take two parameters a1,a2 and compare them and
return true if and only if the first one is considered to go before the
second.
• If you want to sort ascending the compare function must return:
a1 < a2
• If you want to sort descending the compare function must return:
a1 > a2
Reference:
Some STL Algorithms
• There are a lot of build in algorisms on STL these are some of them:
Reference:
DescriptionFunction
Find value in rangefind
Copy range of elementscopy
Fill range with valuefill
Transform rangetransform
Remove consecutive duplicates in rangeunique
Reverse rangereverse
Sort elements in rangesort
Sort elements preserving order of equivalentsstable_sort
Lexicographical less-than comparisonlexicographical_compare
Transform range to next permutationnext_permutation
Transform range to previous permutationprev_permutation
Return distance between iteratorsdistance
Example 2: The Monk and Class Marks
Monk is a multi-talented person, and prepares results for his college in his free
time. (Yes, he is still in love with his old college!) He gets a list of students with
their marks. The maximum marks which can be obtained in the exam is 100.
The Monk is supposed to arrange the list in such a manner that the list is sorted
in decreasing order of marks. And if two students have the same marks, they
should be arranged in lexicographical manner.
Help Monk prepare the same!
Solve At:
Example 2: The Monk and Class Marks
Input:
On the first line of the standard input, there is an integer N, denoting the number
of students. N lines follow, which contain a string and an integer, denoting the
name of the student and his marks.
Output:
You must print the required list.
Constraints:
1 <= N <= 105
1 <= | Length of the name | <= 100
1 <= Marks <= 100
Solve At:
Example 2: The Monk and Class Marks
Sample Input
3
Eve 78
Bob 99
Alice 78
Solve At:
Sample Output
Bob 99
Alice 78
Eve 78
Set container
• Sets are containers that store unique elements following a specific
order.
• In a set, the value of an element also identifies it (the value is itself
the key, of type T), and each value must be unique. The value of the
elements in a set cannot be modified once in the container (the
elements are always const), but they can be inserted or removed
from the container.
• Internally, the elements in a set are always sorted following a
specific strict weak ordering criterion indicated by its internal
comparison object (of type Compare).
• set containers are generally slower than unordered_set containers
to access individual elements by their key, but they allow the direct
iteration on subsets based on their order.
Reference:
Set container
• Set containers don’t allow duplicated elements if you want to allow
duplicated elements use mulitset.
• Sets are typically implemented as binary search trees.
• Some common set functions:
Reference:
DescriptionFunction
Return iterator to beginningbegin
Return iterator to endend
Test whether container is emptyempty
Return container sizesize
Insert elementinsert
Erase elementserase
Clear contentclear
Get iterator to elementfind
Mulitset container
• mulitset containers allow duplicated elements and has all of the set
member functions with some additional functions.
• Some common mulitset functions:
Reference:
DescriptionFunction
Return iterator to lower boundlower_bound
Return iterator to upper boundupper_bound
Get range of equal elementsequal_range
Unordered set container
• unordered_set are containers that store unique elements in no
particular order, and which allow for fast retrieval of individual
elements based on their value.
• In an unordered_set, the value of an element is at the same time its
key, that identifies it uniquely. Keys are immutable, therefore, the
elements in an unordered_set cannot be modified once in the
container - they can be inserted and removed, though.
• Internally, the elements in the unordered_set are not sorted in any
particular order, but organized into buckets depending on their hash
values to allow for fast access to individual elements directly by
their values (with a constant average time complexity on average).
Reference:
Unordered set container
• unordered_set containers are faster than set containers to access
individual elements by their key, although they are generally less
efficient for range iteration through a subset of their elements.
• unordered_set have the same common functions in the set.
• Like the set there is unordered_multiset that allow duplicated
elements and have the same common functions of the multiset.
Reference:
Map container
• Maps are associative containers that store elements formed by a
combination of a key value and a mapped value, following a specific
order.
• In a map, the key values are generally used to sort and uniquely
identify the elements, while the mapped values store the content
associated to this key. The types of key and mapped value may
differ, and are grouped together in member type value_type, which
is a pair type combining both.
• Internally, the elements in a map are always sorted by its key
following a specific strict weak ordering criterion indicated by its
internal comparison object (of type Compare).
Reference:
Map container
• map containers are generally slower than unordered_map
containers to access individual elements by their key, but they allow
the direct iteration on subsets based on their order.
• The mapped values in a map can be accessed directly by their
corresponding key using the bracket operator ((operator[]).
• Maps are typically implemented as binary search trees.
• map containers have the same common functions in the set with
differences in parameters type.
• Like set there is multimap container witch allow duplicated keys and
unordered_map and unordered_multimap which implements hash
table.
Reference:
Example 3: Monk's Birthday Party
Monk's birthday is coming this weekend! He wants to plan a Birthday party and
is preparing an invite list with his friend Puchi. He asks Puchi to tell him names to
add to the list.
Puchi is a random guy and keeps coming up with names of people randomly to
add to the invite list, even if the name is already on the list! Monk hates
redundancy and hence, enlists the names only once.
Find the final invite-list, that contain names without any repetition.
Solve At:
Example 3: Monk's Birthday Party
Input:
First line contains an integer T. T test cases follow.
First line of each test contains an integer N, the number of names that Puchi pops
up with.
Output:
For each testcase, Output the final invite-list with each name in a new line. The
names in the final invite-list are sorted lexicographically.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 105
1 ≤ Length of each name ≤ 105
Solve At:
Example 3: Monk's Birthday Party
Sample Input
1
7
chandu
paro
rahul
mohi
paro
arindam
rahul
Solve At:
Sample Output
arindam
chandu
mohi
paro
rahul
Example 4: Sumsets
Given S, a set of integers, nd the largest d such that a + b + c = d
where a, b, c, and d are distinct elements of S.
Input
Several S, each consisting of a line containing an integer 1 n
1000 indicating the number of elements in S, followed by the elements
of S, one per line. Each element of S is a distinct integer between -
536870912 and +536870911 inclusive.
The last line of input contains `0'.
Output
For each S, a single line containing d, or a single line containing `no solution'.
Solve At:
Example 4: Sumsets
Sample Input
5
2
3
5
7
12
Solve At:
Sample Output
12
Example 5: Ananagrams
Most crossword puzzle fans are used to anagrams--groups of words with the
same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST.
Some words however do not have this attribute, no matter how you rearrange
their letters, you cannot form another word. Such words are called ananagrams,
an example is QUIZ.
Obviously such definitions depend on the domain within which we are working;
you might think that ATHENE is an ananagram, whereas any chemist would
quickly produce ETHANE. One possible domain would be the entire English
language, but this could lead to some problems. One could restrict the domain
to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not
in the same domain) but NOTE is not since it can produce TONE.
Solve At:
Example 5: Ananagrams
Write a program that will read in the dictionary of a restricted domain and
determine the relative ananagrams. Note that single letter words are, ipso facto,
relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will
contain no more than 1000 words.
Solve At:
Example 5: Ananagrams
Input: Input will consist of a series of lines. No line will be more than 80
characters long, but may contain any number of words. Words consist of up to 20
upper and/or lower case letters, and will not be broken across lines. Spaces may
appear freely around words, and at least one space separates multiple words on
the same line. Note that words that contain the same letters but of differing case
are considered to be anagrams of each other, thus tIeD and EdiT are anagrams.
The file will be terminated by a line consisting of a single #.
Output : Output will consist of a series of lines. Each line will consist of a single
word that is a relative ananagram in the input dictionary. Words must be output
in lexicographic (case-sensitive) order. There will always be at least one relative
ananagram.
Solve At:
Example 5: Ananagrams
Sample Input
ladder came tape soon leader acme
RIDE lone Dreis peat
ScAlE orb eye Rides dealer NotE
derail LaCeS drIed
noel dire Disk mace Rob dries
#
Solve At:
Sample Output
Disk
NotE
derail
drIed
eye
ladder
soon
Thank you :) :) :)

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Data types in python
Data types in pythonData types in python
Data types in python
 
String
StringString
String
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
 
Arrays
ArraysArrays
Arrays
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
1-D array
1-D array1-D array
1-D array
 
Python data type
Python data typePython data type
Python data type
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithms
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
 
Array
ArrayArray
Array
 
Sorting
SortingSorting
Sorting
 
Arrays
ArraysArrays
Arrays
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 

Ähnlich wie Acm aleppo cpc training seventh session

Ähnlich wie Acm aleppo cpc training seventh session (20)

Array ppt
Array pptArray ppt
Array ppt
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
arrayppt.pptx
arrayppt.pptxarrayppt.pptx
arrayppt.pptx
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
array.ppt
array.pptarray.ppt
array.ppt
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf
 
Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
Unit 4
Unit 4Unit 4
Unit 4
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth session
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 

Mehr von Ahmad Bashar Eter

Acm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAcm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAhmad Bashar Eter
 
Acm aleppo cpc training eighth session
Acm aleppo cpc training eighth sessionAcm aleppo cpc training eighth session
Acm aleppo cpc training eighth sessionAhmad Bashar Eter
 
Acm aleppo cpc training fifth session
Acm aleppo cpc training fifth sessionAcm aleppo cpc training fifth session
Acm aleppo cpc training fifth sessionAhmad Bashar Eter
 
Acm aleppo cpc training third session
Acm aleppo cpc training third sessionAcm aleppo cpc training third session
Acm aleppo cpc training third sessionAhmad Bashar Eter
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second sessionAhmad Bashar Eter
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Ahmad Bashar Eter
 

Mehr von Ahmad Bashar Eter (6)

Acm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAcm aleppo cpc training ninth session
Acm aleppo cpc training ninth session
 
Acm aleppo cpc training eighth session
Acm aleppo cpc training eighth sessionAcm aleppo cpc training eighth session
Acm aleppo cpc training eighth session
 
Acm aleppo cpc training fifth session
Acm aleppo cpc training fifth sessionAcm aleppo cpc training fifth session
Acm aleppo cpc training fifth session
 
Acm aleppo cpc training third session
Acm aleppo cpc training third sessionAcm aleppo cpc training third session
Acm aleppo cpc training third session
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 

Kürzlich hochgeladen

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Kürzlich hochgeladen (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Acm aleppo cpc training seventh session

  • 1. ACM Aleppo CPC Training Part 1 C++ Programming Concepts By Ahmad Bashar Eter
  • 2. Reminder This is the most used containers: vector : dynamic array list : linked list data structure set : a sorted binary search tree map : associated container a sorted binary search tree unordedset : hash table unordedmap : associated container hash table queue : queue data structure stack : stack data structure priority queue : max heap data structure Reference:
  • 3. Example 1: Array Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of all numbers in the third set is equal to zero. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Solve At:
  • 4. Example 1: Array Input: The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an(|ai| ≤ 103) — the array elements. Output: In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Solve At:
  • 5. Example 1: Array Sample Input 3 -1 2 0 Solve At: Sample Output 1 -1 1 2 1 0
  • 6. Some STL Algorithms • We have seen so far how to sort data in ascending order we. • Some time we need to sort data in special way, in order to customize our sort algorithm we can give the sort algorithm a predict function that tell the algorithm if two element are in the right order or not. • This function take two parameters a1,a2 and compare them and return true if and only if the first one is considered to go before the second. • If you want to sort ascending the compare function must return: a1 < a2 • If you want to sort descending the compare function must return: a1 > a2 Reference:
  • 7. Some STL Algorithms • There are a lot of build in algorisms on STL these are some of them: Reference: DescriptionFunction Find value in rangefind Copy range of elementscopy Fill range with valuefill Transform rangetransform Remove consecutive duplicates in rangeunique Reverse rangereverse Sort elements in rangesort Sort elements preserving order of equivalentsstable_sort Lexicographical less-than comparisonlexicographical_compare Transform range to next permutationnext_permutation Transform range to previous permutationprev_permutation Return distance between iteratorsdistance
  • 8. Example 2: The Monk and Class Marks Monk is a multi-talented person, and prepares results for his college in his free time. (Yes, he is still in love with his old college!) He gets a list of students with their marks. The maximum marks which can be obtained in the exam is 100. The Monk is supposed to arrange the list in such a manner that the list is sorted in decreasing order of marks. And if two students have the same marks, they should be arranged in lexicographical manner. Help Monk prepare the same! Solve At:
  • 9. Example 2: The Monk and Class Marks Input: On the first line of the standard input, there is an integer N, denoting the number of students. N lines follow, which contain a string and an integer, denoting the name of the student and his marks. Output: You must print the required list. Constraints: 1 <= N <= 105 1 <= | Length of the name | <= 100 1 <= Marks <= 100 Solve At:
  • 10. Example 2: The Monk and Class Marks Sample Input 3 Eve 78 Bob 99 Alice 78 Solve At: Sample Output Bob 99 Alice 78 Eve 78
  • 11. Set container • Sets are containers that store unique elements following a specific order. • In a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be unique. The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container. • Internally, the elements in a set are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare). • set containers are generally slower than unordered_set containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order. Reference:
  • 12. Set container • Set containers don’t allow duplicated elements if you want to allow duplicated elements use mulitset. • Sets are typically implemented as binary search trees. • Some common set functions: Reference: DescriptionFunction Return iterator to beginningbegin Return iterator to endend Test whether container is emptyempty Return container sizesize Insert elementinsert Erase elementserase Clear contentclear Get iterator to elementfind
  • 13. Mulitset container • mulitset containers allow duplicated elements and has all of the set member functions with some additional functions. • Some common mulitset functions: Reference: DescriptionFunction Return iterator to lower boundlower_bound Return iterator to upper boundupper_bound Get range of equal elementsequal_range
  • 14. Unordered set container • unordered_set are containers that store unique elements in no particular order, and which allow for fast retrieval of individual elements based on their value. • In an unordered_set, the value of an element is at the same time its key, that identifies it uniquely. Keys are immutable, therefore, the elements in an unordered_set cannot be modified once in the container - they can be inserted and removed, though. • Internally, the elements in the unordered_set are not sorted in any particular order, but organized into buckets depending on their hash values to allow for fast access to individual elements directly by their values (with a constant average time complexity on average). Reference:
  • 15. Unordered set container • unordered_set containers are faster than set containers to access individual elements by their key, although they are generally less efficient for range iteration through a subset of their elements. • unordered_set have the same common functions in the set. • Like the set there is unordered_multiset that allow duplicated elements and have the same common functions of the multiset. Reference:
  • 16. Map container • Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order. • In a map, the key values are generally used to sort and uniquely identify the elements, while the mapped values store the content associated to this key. The types of key and mapped value may differ, and are grouped together in member type value_type, which is a pair type combining both. • Internally, the elements in a map are always sorted by its key following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare). Reference:
  • 17. Map container • map containers are generally slower than unordered_map containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order. • The mapped values in a map can be accessed directly by their corresponding key using the bracket operator ((operator[]). • Maps are typically implemented as binary search trees. • map containers have the same common functions in the set with differences in parameters type. • Like set there is multimap container witch allow duplicated keys and unordered_map and unordered_multimap which implements hash table. Reference:
  • 18. Example 3: Monk's Birthday Party Monk's birthday is coming this weekend! He wants to plan a Birthday party and is preparing an invite list with his friend Puchi. He asks Puchi to tell him names to add to the list. Puchi is a random guy and keeps coming up with names of people randomly to add to the invite list, even if the name is already on the list! Monk hates redundancy and hence, enlists the names only once. Find the final invite-list, that contain names without any repetition. Solve At:
  • 19. Example 3: Monk's Birthday Party Input: First line contains an integer T. T test cases follow. First line of each test contains an integer N, the number of names that Puchi pops up with. Output: For each testcase, Output the final invite-list with each name in a new line. The names in the final invite-list are sorted lexicographically. Constraints: 1 ≤ T ≤ 10 1 ≤ N ≤ 105 1 ≤ Length of each name ≤ 105 Solve At:
  • 20. Example 3: Monk's Birthday Party Sample Input 1 7 chandu paro rahul mohi paro arindam rahul Solve At: Sample Output arindam chandu mohi paro rahul
  • 21. Example 4: Sumsets Given S, a set of integers, nd the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each consisting of a line containing an integer 1 n 1000 indicating the number of elements in S, followed by the elements of S, one per line. Each element of S is a distinct integer between - 536870912 and +536870911 inclusive. The last line of input contains `0'. Output For each S, a single line containing d, or a single line containing `no solution'. Solve At:
  • 22. Example 4: Sumsets Sample Input 5 2 3 5 7 12 Solve At: Sample Output 12
  • 23. Example 5: Ananagrams Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams, an example is QUIZ. Obviously such definitions depend on the domain within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE. Solve At:
  • 24. Example 5: Ananagrams Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will contain no more than 1000 words. Solve At:
  • 25. Example 5: Ananagrams Input: Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. The file will be terminated by a line consisting of a single #. Output : Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always be at least one relative ananagram. Solve At:
  • 26. Example 5: Ananagrams Sample Input ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides dealer NotE derail LaCeS drIed noel dire Disk mace Rob dries # Solve At: Sample Output Disk NotE derail drIed eye ladder soon
  • 27. Thank you :) :) :)