Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program Shipping You finally achieved your dream of managing Omazans large convoy of ships; its so futuristic its next gen shipping. These ships carry

C program

Shipping

You finally achieved your dream of managing Omazans large convoy of ships; its so futuristic its next gen shipping. These ships carry good across the globe. Ships will send in requests to join and leave your convoy, and traders will query the contents of the convoy (either the goods on ships and potentially the ids of said ships). Your job is to write program which stores all this information and services the traders strange inquiries. As an example you could have the following set of ships,

Ship 3 being the first ship in the convoy. To prevent nautical accidents from happening, you only allow ships to leave when they are the last ship in the convoy. If ship 3 requests to leave (note its not the last ship in the convoy), it wont be able to immediately. For this reason, when Ship 3 requests to leave it will swap positions with ship 4, and then depart from the convoy. A trader does not know the ids of the ships, so they might request the id of a ship at a location in the convoy. Alternatively, a trader may request the name of an item in some particular container of a specified ship (by location starting index at 1). Suppose we have the original convoy of ships 3, 5, and 4. Imagine a trader asks what the 1stships 4thgood is. The 1stship has Ship ID 3. The 4th good is Grain. For this reason, Grain would be reported to the trader. If a trader asks for a ship or container not in the convoy, you should report that the ship-container request is not valid.

Input Specification

Each line of input describes either an event or contains the integer -1. If a ship wishes to leave, the event begins with the integer 0 (zero). Following the integer 0, the id of the ship (1 indexed) will be given. The id given will be a valid ship in the convoy. If a ship wishes to join the convoy, the event begins with the integer 1 (one). Following the integer 1, a positive integer, n, representing the number of containers on the ship will be given. Following n will be n (n 10,000) space separated container descriptions. Each container description will be composed of two values a positive integer k (k 100) representing the number of alphanumeric characters in the containers name and a string composed of only k alphanumeric characters.

If a trader requests the id of a ship in some position of the Convoy, the event begins with the integer 2 (two). Following the integer 2, the position of the ship in the convoy will be given. You will need to output the id for such a request. If a trader requests the contents of some container, the event begins with the integer 3 (three). Following the integer 3, the position of the ship in the convoy will be given. Following the ship position will be an integer representing the container position requested. If the request in the input is just the value -1 then the program should exit with a successful return code.

Output Specification

For each trader event (type 2 and type 3) you will need to output a line with some value. In type 2 you will output the id of the ship at the given position. If the ship position is invalid output a -1 instead. In type 3 yowl output the name of the contents of a container at the given position. If the ship/container position is invalid output a -1 instead.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

Input Output Example Output AnotherShip Input 1 1 3 Dog 1 2 5 AShip 11 AnotherShip 1 4 5 Cocoa 5 Sugar 5 Sugar 5 Grain 0 1 3 2 2 1 2 4 Corn 6 Carrot 2 1 4 2 Corn Grain 2 3 1 6 3 Car 3 Car 3 Car 3 Car 3 Car 3 Car 0 2 3 3 1 3 1 4 3 4 1 1 1 3 DOG 1 1 3 CAT 1 5 1 A 1 B1 C1 D 1 E 3 1 1 3 3 1 3 3 5 3 1 5 0 2 DOG

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions