C Program for Blazcar Roads Intersections Problem
Project Description
In this project, you will write a C (C89) program that, given an input file containing road data (road name, nearest intersection, length) and data of merged road (nearest intersection, length); outputs a file with the best possible rank for each road (in descending order of length) if a merged road were assigned as part of its length.
Overview:
Blazcar is a town in a mountain which has many roads that reach downtown. To identify the roads, each one bears the name of a resident. A road is usually connected to another and the point where two or more roads meet is called an intersection. If an intersection is not downtown, the merged part of the road could take the name of any of the roads that were merged, so the length of a road can be calculated with this method.
Figure 1 shows an example of 6 roads in Blazcar. The numbers are the length of each road segment. The green circles are the intersections and their corresponding ID.
When a list of roads is arranged in descending order of length, the top-ranked road is assigned the rank of 1, representing the longest path. Figure 1 illustrates a naming convention presented to the residents, although some are dissatisfied that their names were not selected for the merged roads. They argue that if their names had been chosen, their roads would have been longer. For instance, if the merged road "Vegeta-Piccolo" were named simply "Vegeta," the length of the "Vegeta" road would total 688 (335+353), while the "Piccolo" road would be 305 units long.
Residents who believe that their names should be assigned to merged roads have argued that such assignments would consistently secure either rank 1 or 2. To address this assumption, you will assist the Blazcar team in determining the optimal rank for each road across all potential naming scenarios for merged roads. In cases of ties, all roads sharing the same length will be assigned the same rank. For instance, if one road is the longest and all other roads have equal lengths, they will all be ranked 2.
Input:
Each input file may include multiple test cases, and each test case begins with the first line comprising two integers, n and m. These values correspond to the number of roads, n (with a range of 1 to 500,000), and the number of intersections, m (with a range from 1 to n-1), excluding the downtown intersection.
Following the initial line, the next n lines provide descriptions of the roads. These lines include the name of the road, as well as two integers, c and d. Road names consist of letters only, with a maximum length of 10 characters. The integer c (with a range from 0 to m) signifies the ID of the nearest intersection, while d (with a range from 0 to 2000) denotes the distance in kilometers from that road to the intersection.
Subsequently, the next m lines detail the data for each intersection c in ascending order, ranging from 1 to m. These lines comprise two integers: the nearest intersection and the distance between these points, expressed in kilometers.
The conclusion of the test case(s) is indicated by a line containing two zeros.
Output:
The program will generate the results in an output file with the same name as the input file, but with the ".out" extension. Upon successful execution, the program will display the message "Output file: <output_file.out> created successfully."
Within the output file, each instance is labeled as "Instance #:" where # corresponds to the test case number (starting from 1 for the first case). Subsequently, for each road, a line will be displayed containing the road name and its optimal rank, separated by a space. The order of these lines mirrors the order in the input.
Requirements:
- Do not include blank lines in output files.
- Verify the number of command line arguments, if it is not correct, display an Err Msg, and exit the program: "Error! You must specify input filename: ./program <input_filename>"
- Verify that your program can open the buffer space for a file (fopen), otherwise display an Err Msg, and exit the program: "Error! The <filename> file can't be opened"
- Global variables are not allowed.
Run Example:
To run your program, you must specify the name of the input file in the command line. Assume your executable file is “program” and the input file name is input.txt, and the input file is in the same working directory as your executable. Here is a run example of the program:
./program Error! You must specify input filename: ./program <input_filename> ./program xyz.txt Error! The xyz.txt file can't be opened ./program input.txt Output file: output.out created successfully
Example Input File (input.txt):
6 2 Bulma 0 513 Frieza 2 675 Yamcha 2 700 Vegeta 1 335 Piccolo 1 305 Goku 0 765 0 353 0 65 0 0
Example Output File (output.out):
Instance 1: Bulma 5 Frieza 2 Yamcha 1 Vegeta 3 Piccolo 4 Goku 1
Description of input.txt
The first line of the input file are values for: n, m. There are 6 roads (n is 6), and 2 intersections excluding the downtown intersection (m is 2). The next 6 lines consist of road information. For example, the road name is Bulma, the nearest intersection is 0 (downtown), and the length from the beginning of the road to that intersection is 513 km. The next line indicates the road name is Frieza, the nearest intersection is 2, and the length from the beginning of the road to that intersection is 675. After the data of the roads, the next 2 lines (m is 2) are the information of each intersection. Thus 0 353 corresponds to intersection 1; where 0 is the nearest intersection to intersection 1 and 353 is the length of that segment. Similarly, 0 65 is the data of intersection 2.
Description of output.out
Since the entry only has one instance; The output only provides the solution for Instance 1: The output shows the 6 road names (in the same order as indicated in the input) along with their best possible rank after analysis of all named schemes. For example, you can see that Vegeta can get rank 3 if his merged road between intersections 1 and 0 is named after him, which is a better rank than shown in Figure 1.
Terms and Conditions
No refund will be provided as the file is non returnable.
A single .c file will be delivered, adhering to the specifications outlined in the provided problem description, with the exception that specific limits for the number of roads, intersections, intersection IDs, and road name character limits will not be implemented. This deviation is due to the absence of guidance in the problem description regarding how to handle cases when these limits are not met, or when an allocation for a data structure to accommodate 500,000 roads is required.
Assumptions detailed in the problem description will not be enforced as they are based on assumptions, and the problem description does not provide instructions for addressing scenarios where these assumptions are not met.
You acknowledge that you have viewed a video demonstrating program execution, confirming that it aligns with the specifications outlined in this offer and that the program functions satisfactorily.
You also understand that the seller is not responsible for making any changes to the program if it ceases to function correctly after purchase, nor is the seller obligated to implement any new modifications beyond those explicitly mentioned in this problem description.
It is explicitly prohibited to resell, distribute, recreate, or remix this program in any way.
The program will be delivered exclusively through Discord.
The program will only be delivered upon receipt of your payment and your explicit request for the file via Discord; it will not be automatically or instantly delivered.
You acknowledge that the program will not be provided until you explicitly request it through Discord chat, and it will not be delivered instantly.
You acknowledge , Delivery time may vary and can take from a few minutes to a few hours, or more, in some cases.
Comments
Post a Comment