Problem: Given a list of commands determine at particular points what animal is contained in a requested cage. Input: will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park sections. Each park section initially contains 0 cages. Following this line will be list of commands. The commands must be processed in the order they are given. Each command begins with a number and can be 1 of 4 types. The types are listed below ●1 S C ○This command changes the number of cages in some particular section. The section that is modified is the section numbered S (1-indexed). The resulting number of cages in section S is the number C. This could increase or decrease the number of cages. Any animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the section number is invalid, no changes should be made. ●2 S C A ○This command adds an animal to a cage. The section that is modified is the section numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the cage is empty and the section and cage exists. If an animal is already present in cage C of section S or there is no section S or cage C of section S does not exist, then the animal is NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric characters). ●3 S C ○This command requests the animal type of the animal in cage C (1-indexed) of section S. If no animal is present or the section or cage number is invalid, the phrase “No animal found.” (quotes for clarity) should be printed instead. ●4 ○This command requests that the program ends (I guess we finished organizing all the exhibits). Output: should contain a line for each command of type 3. The line should either contain the animal type if the request was valid or the string “No animal found.”
Problem: Given a list of commands determine at particular points what animal is contained in a requested cage. Input: will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park sections. Each park section initially contains 0 cages. Following this line will be list of commands. The commands must be processed in the order they are given. Each command begins with a number and can be 1 of 4 types. The types are listed below ●1 S C ○This command changes the number of cages in some particular section. The section that is modified is the section numbered S (1-indexed). The resulting number of cages in section S is the number C. This could increase or decrease the number of cages. Any animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the section number is invalid, no changes should be made. ●2 S C A ○This command adds an animal to a cage. The section that is modified is the section numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the cage is empty and the section and cage exists. If an animal is already present in cage C of section S or there is no section S or cage C of section S does not exist, then the animal is NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric characters). ●3 S C ○This command requests the animal type of the animal in cage C (1-indexed) of section S. If no animal is present or the section or cage number is invalid, the phrase “No animal found.” (quotes for clarity) should be printed instead. ●4 ○This command requests that the program ends (I guess we finished organizing all the exhibits). Output: should contain a line for each command of type 3. The line should either contain the animal type if the request was valid or the string “No animal found.”
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter8: Working With Trendlines, Pivottables, Pivotcharts, And Slicers
Section: Chapter Questions
Problem 8EYK
Related questions
Question
I need help writing this code in C using dyanmic memory and structs.
Problem: Given a list of commands determine at particular points what animal is contained in a requested cage.
Input: will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park
sections. Each park section initially contains 0 cages.
Following this line will be list of commands. The commands must be processed in the order they are
given. Each command begins with a number and can be 1 of 4 types. The types are listed below
●1 S C
○This command changes the number of cages in some particular section. The section that
is modified is the section numbered S (1-indexed). The resulting number of cages in
section S is the number C. This could increase or decrease the number of cages. Any
animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the
section number is invalid, no changes should be made.
●2 S C A
○This command adds an animal to a cage. The section that is modified is the section
numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the
cage is empty and the section and cage exists. If an animal is already present in cage C of
section S or there is no section S or cage C of section S does not exist, then the animal is
NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric
characters).
●3 S C
○This command requests the animal type of the animal in cage C (1-indexed) of section S.
If no animal is present or the section or cage number is invalid, the phrase “No animal
found.” (quotes for clarity) should be printed instead.
●4
○This command requests that the program ends (I guess we finished organizing all the
exhibits).
sections. Each park section initially contains 0 cages.
Following this line will be list of commands. The commands must be processed in the order they are
given. Each command begins with a number and can be 1 of 4 types. The types are listed below
●1 S C
○This command changes the number of cages in some particular section. The section that
is modified is the section numbered S (1-indexed). The resulting number of cages in
section S is the number C. This could increase or decrease the number of cages. Any
animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the
section number is invalid, no changes should be made.
●2 S C A
○This command adds an animal to a cage. The section that is modified is the section
numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the
cage is empty and the section and cage exists. If an animal is already present in cage C of
section S or there is no section S or cage C of section S does not exist, then the animal is
NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric
characters).
●3 S C
○This command requests the animal type of the animal in cage C (1-indexed) of section S.
If no animal is present or the section or cage number is invalid, the phrase “No animal
found.” (quotes for clarity) should be printed instead.
●4
○This command requests that the program ends (I guess we finished organizing all the
exhibits).
Output: should contain a line for each command of type 3. The line should either contain the animal type if
the request was valid or the string “No animal found.”
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L