SlideShare a Scribd company logo
ACM Aleppo CPC Training
Part 1 C++ Programming Concepts
By Ahmad Bashar Eter
Strings:
• We’ve seen that the strings is a type that represent array of
characters.
• We’ve also seen that if we want to input a string we can use the
default cin with >> operator but this method input the first part of
the string until the first white space character.
• If we want to input a full line string we may use getline function.
• Note: sometimes the getline retune empty string because of some
characters in the cin buffer so in order to ensure good usage of the
function put cin.clear(); cin.ignore(); before you use getline.
• Or another method is to put the getline in while loop while the
string is empty.
• We will continue on the C++ string object and its functions.
Strings:
DescriptionFunction
Return iterator to beginningbegin
Return iterator to endend
Return length of stringlength, size
Clear stringclear
Test if string is emptyempty
Append to stringappend
Insert into stringinsert
Find content in stringfind
Erase characters from stringerase
Get C string equivalentc_str
For the full reference go to:
Sort Algorithm:
• A lot of problems can be solved easily if the input is sorted.
• So in order to sort any sequence of elements we may use the
function sort which exist in the C++ algorithms library.
• this function take 2 parameter pointer or iterator to the first
element and pointer or iterator to the end of the sequence.
• Note the end element is the first element out side the rang or the
sequence.
• Know we will take the rest of the session to solve problems.
Example 1: 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 1: 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:
Example 2: Little Elephant and Chess
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces
but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either
black or white. The Little Elephant and his friend know that a proper chessboard doesn't have
any side-adjacent cells with the same color and the upper left cell is white. To play chess, they
want to make the board they have a proper chessboard. For that the friends can choose any
row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost)
square on the first place in the row and shift the others one position to the right. You can run
the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the
line are marked with character "W", the black cells are marked with character "B"), then after
one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the
described operations to turn the board they have into a proper chessboard.
Solve at:
Example 2: Little Elephant and Chess
Input
The input consists of exactly eight lines. Each line contains exactly eight
characters "W" or "B" without any spaces: the j-th character in the i-th line
stands for the color of the j-th cell of the i-th row of the elephants' board.
Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and
the columns — from 1 to 8 from left to right. The given board can initially be a
proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a
proper chessboard and "NO" (without the quotes) otherwise.
Solve at:
Example 3: Checking the Calendar
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first
day of some month was equal to the first day of the week you are given, while the
first day of the next month was equal to the second day of the week you are
given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of
months in this calendar is equal to 12. The number of days in months during any
non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday",
"tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Solve at:
Example 3: Checking the Calendar
Input
The input consists of two lines, each of them containing the name of exactly one
day of the week. It's guaranteed that each string in the input is from the set
"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Output
Print "YES" (without quotes) if such situation is possible during some non-leap
year. Otherwise, print "NO" (without quotes).
Solve at:
Example 4: Boy or Girl
Those days, many boys use beautiful girls' photos as avatars in forums. So it is
pretty hard to tell the gender of a user at the first glance. Last year, our hero
went to a forum and had a nice chat with a beauty (he thought so). After that
they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is
actually a very strong man! Our hero is very sad and he is too tired to love again
now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd,
then he is a male, otherwise she is a female. You are given the string that
denotes the user name, please help our hero to determine the gender of this
user by his method.
Solve at:
Example 4: Boy or Girl
Input
The first line contains a non-empty string, that contains only lowercase English
letters — the user name. This string contains at most 100 letters.
Output
If it is a female by our hero's method, print "CHAT WITH HER!" (without the
quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Solve at:
Example 5: Amusing Joke
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and
have guests at last. When two "New Year and Christmas Men" meet, thear assistants
cut out of cardboard the letters from the guest's name and the host's name in honor of
this event. Then the hung the letters above the main entrance. One night, when
everyone went to bed, someone took all the letters of our characters' names. Then he
may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But
everybody wondered whether it is possible to restore the names of the host and his
guests from the letters lying at the door? That is, we need to verify that there are no
extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem.
You are given both inscriptions that hung over the front door the previous night, and a
pile of letters that were found at the front door next morning.
Solve at:
Example 5: Amusing Joke
Input
The input file consists of three lines: the first line contains the guest's name, the
second line contains the name of the residence host and the third line contains
letters in a pile that were found at the door in the morning. All lines are not empty
and contain only uppercase Latin letters. The length of each line does not
exceed 100.
Output
Print "YES" without the quotes, if the letters in the pile could be permuted to make
the names of the "New Year and Christmas Men". Otherwise, print "NO" without
the quotes.
Solve at:
Other Exercises
Try these good exercises and remember the more you exercise, the
better you will become ;).
• Codeforces B. Pashmak and Flowers
• Codeforces A. Laptops
• Codeforces A. Wsay Too Long Words
• Codeforces A. String Task
And don’t forget to join the Facebook group:
Acm_Aleppo_CPC | Discussion
Also follow us on:
ACM ICPC Aleppo University
Thank you :) :) :)

More Related Content

DOC
11 plus verbal reasoning - Overview
PDF
Application of HCR's Rank Formula on color property of articles
DOC
Grammar 1
DOCX
1 ECE 175 Computer Programming for Engineering Applica.docx
DOCX
Conditional structure
PDF
07-Strings( string Functions and parameters C).pdf
PDF
Septocode 2021 editorial
DOCX
C# problems
11 plus verbal reasoning - Overview
Application of HCR's Rank Formula on color property of articles
Grammar 1
1 ECE 175 Computer Programming for Engineering Applica.docx
Conditional structure
07-Strings( string Functions and parameters C).pdf
Septocode 2021 editorial
C# problems

Similar to Acm aleppo cpc training third session (20)

DOCX
String based programming puzzles solved
PDF
Questions4
PDF
Python assignment 4
DOCX
© Copyright 2013 by Pearson Education, Inc. All Rights Res.docx
DOC
Data structure
PDF
C Code and the Art of Obfuscation
PDF
Amcat automata questions
PDF
Amcat automata questions
PPS
C programming session 02
DOCX
Assignment SpecificationsYou must implement a simplified version .docx
PDF
Erlang Introduction
DOC
Ramco Sample Paper 2003
PDF
Microsoft Word Hw#1
PPTX
Recursive Functions in Python - Assignment Sample for University Students
PPT
PDF
A01
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
PDF
Computer Science Paper 1 (Theory) - 2017.pdf
PDF
Computer Science Paper 1 (Theory) - 2019 (1).pdf
String based programming puzzles solved
Questions4
Python assignment 4
© Copyright 2013 by Pearson Education, Inc. All Rights Res.docx
Data structure
C Code and the Art of Obfuscation
Amcat automata questions
Amcat automata questions
C programming session 02
Assignment SpecificationsYou must implement a simplified version .docx
Erlang Introduction
Ramco Sample Paper 2003
Microsoft Word Hw#1
Recursive Functions in Python - Assignment Sample for University Students
A01
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Computer Science Paper 1 (Theory) - 2017.pdf
Computer Science Paper 1 (Theory) - 2019 (1).pdf
Ad

More from Ahmad Bashar Eter (7)

PDF
Acm aleppo cpc training ninth session
PDF
Acm aleppo cpc training eighth session
PDF
Acm aleppo cpc training seventh session
PDF
Acm aleppo cpc training sixth session
PDF
Acm aleppo cpc training fifth session
PDF
Acm aleppo cpc training second session
PDF
Acm aleppo cpc training introduction 1
Acm aleppo cpc training ninth session
Acm aleppo cpc training eighth session
Acm aleppo cpc training seventh session
Acm aleppo cpc training sixth session
Acm aleppo cpc training fifth session
Acm aleppo cpc training second session
Acm aleppo cpc training introduction 1
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Lesson notes of climatology university.
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
RMMM.pdf make it easy to upload and study
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Sports Quiz easy sports quiz sports quiz
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism
Anesthesia in Laparoscopic Surgery in India
Lesson notes of climatology university.
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
RMMM.pdf make it easy to upload and study
Microbial disease of the cardiovascular and lymphatic systems
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Sports Quiz easy sports quiz sports quiz
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPH.pptx obstetrics and gynecology in nursing
STATICS OF THE RIGID BODIES Hibbelers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Pre independence Education in Inndia.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf

Acm aleppo cpc training third session

  • 1. ACM Aleppo CPC Training Part 1 C++ Programming Concepts By Ahmad Bashar Eter
  • 2. Strings: • We’ve seen that the strings is a type that represent array of characters. • We’ve also seen that if we want to input a string we can use the default cin with >> operator but this method input the first part of the string until the first white space character. • If we want to input a full line string we may use getline function. • Note: sometimes the getline retune empty string because of some characters in the cin buffer so in order to ensure good usage of the function put cin.clear(); cin.ignore(); before you use getline. • Or another method is to put the getline in while loop while the string is empty. • We will continue on the C++ string object and its functions.
  • 3. Strings: DescriptionFunction Return iterator to beginningbegin Return iterator to endend Return length of stringlength, size Clear stringclear Test if string is emptyempty Append to stringappend Insert into stringinsert Find content in stringfind Erase characters from stringerase Get C string equivalentc_str For the full reference go to:
  • 4. Sort Algorithm: • A lot of problems can be solved easily if the input is sorted. • So in order to sort any sequence of elements we may use the function sort which exist in the C++ algorithms library. • this function take 2 parameter pointer or iterator to the first element and pointer or iterator to the end of the sequence. • Note the end element is the first element out side the rang or the sequence. • Know we will take the rest of the session to solve problems.
  • 5. Example 1: 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:
  • 6. Example 1: 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:
  • 7. Example 2: Little Elephant and Chess The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all). For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW". Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard. Solve at:
  • 8. Example 2: Little Elephant and Chess Input The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color. Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard. Output In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. Solve at:
  • 9. Example 3: Checking the Calendar You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year. In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31. Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". Solve at:
  • 10. Example 3: Checking the Calendar Input The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". Output Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). Solve at:
  • 11. Example 4: Boy or Girl Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Solve at:
  • 12. Example 4: Boy or Girl Input The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Solve at:
  • 13. Example 5: Amusing Joke So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Solve at:
  • 14. Example 5: Amusing Joke Input The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Solve at:
  • 15. Other Exercises Try these good exercises and remember the more you exercise, the better you will become ;). • Codeforces B. Pashmak and Flowers • Codeforces A. Laptops • Codeforces A. Wsay Too Long Words • Codeforces A. String Task And don’t forget to join the Facebook group: Acm_Aleppo_CPC | Discussion Also follow us on: ACM ICPC Aleppo University
  • 16. Thank you :) :) :)