Define a prefix of a string is a substring string

Assignment Help Computer Engineering
Reference no: EM1335443

Shortest Prefixes

Input: Prefix .in
Output: Prefix .out

A prefix of a string is a substring string at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", car", "carb", "carbo", and "carbon". Note that the empty string is not considered a prefix in this problem, but every non-empty string is considered to be a prefix of itself. In everyday language, we tend to abbreviate words by prefixes. For example, "carbohydrate "is commonly abbreviated by "carb". In this problem, given a set of words, you will find for each word the shortest prefix that uniquely identifies the word it represents.

In the sample input below, "carbohydrate" can be abbreviated to "carboh", but it cannot be abbreviated to "carbo" (or anything shorter) because there are other words in the list that begin with "carbo".

An exact match will override a prefix match. For example, the prefix "car" matches the given word "car" exactly. Therefore, it is understood without ambiguity that "car" is an abbreviation for "car", not for "carriage" or any of the other words in the list that begins with "car"

"" Input ""

The input file contains at least two, but no more than 1000 lines. Each line contains one word consisting of 1 to 20 lower case letters.

"" Output ""

The output file contains the same number of lines as the input file. Each line of the output file contains the word from the corresponding line of the input file, followed by one blank space; and the shortest prefix that uniquely (without ambiguity) identifies this word.

"" Sample input ""

carbohydrate
cart
carburetor
caramel
caribou
carbonic
cartilage
carbon
carriage
carton
car
carbonate

"" Output for sample input ""

carbohydrate carboh
cart cart
carburetor carbu
caramel cara
caribou cari
carbonic carboni
cartilage carti
carbon carbon
carriage carr
carton carto
car car
carbonate carbona

Reference no: EM1335443

Questions Cloud

The checksum field in a single parity bit scheme : What will be the value of the checksum field b for the case of a two-dimensional parity scheme? Your answer should be such that a minimum-length checksum is used.
Illustrate what is the logic of a firm setting : Illustrate what is the logic of a firm setting and exercising the application of a mandatory retirement age? What are the pros and cons of the mandatory retirement practice from the perspective.
Cross price elasticity of demand : Cross price elasticity of demand
Effectively managing the execution of a project : How do these traits contribute to effectively managing the execution of a project?
Define a prefix of a string is a substring string : An exact match will override a prefix match. For instance, the prefix "car" matches the given word "car" exactly. Therefore, it is understood without ambiguity that "car" is an abbreviation for "car", not for "carriage" or any of the other words i..
Suppose that the ecomony is operating below full employment : Suppose that the ecomony is operating below full employment and that it will not overheat during the year.
Write down a program that reads product number : The Rinky Dooflingy Company manufactures different types of doofingies, each identified b a product number.
Demand analysis : Demand Analysis
Illustrate what the government should do about it : Illustrate what the government should do about it, how would each economist explain unemployment and what policies would each advocate.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Developing the function to list software installed on system

Write down a function which list the software (name and vendor) installed over the computer specified by the input argument. The function should output the list to screen and output the list to the CSV file.

  Define coding of binary information and error detection

define Coding of Binary Information and Error Detection.

  What is the largest value of x

A soft real-time system has four periodic events with periods of 50, 100, 200 and 250 msec each. assume four events require 35, 20, 10 and X msec of CPU time, respectively. What is the largest value of X for which the system is schedulable.

  How to develop a simple scientific calculator

make a Clear button to clear the result text box and reset all controls.

  Write down a class grade with a method getnumericgrade

note down  a Java program that translates a letter grade into a number grade. Letter grades are A B C D F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by 0.3, a - d..

  Give appropriate accessor methods to set and get the data

create an address book application to keep track of the names, addresses, phone numbers, and birthdays of family, friends, and colleagues. You may implement your own linked list library, but it is recommended that you make use of the linked list A..

  Program to find smaller between num1 and num2 to output

Program to find smaller between num1 and num2 to output

  Make use of a for loop to step through all 32 bits

The bitwise-manipulation operators perform simultaneous bit manipulations and enable programs to process large quantities of binary information well.

  Excel supports nesting of functions

Excel supports nesting of functions within one another. Why is that helpful ? Offer some examples of when you would and would not want to use nesting.

  Design a flowchart of the program

The Unit 4 Topic 2 Presentation includes pseudo-code for a program which processes a client file (the master file) and a service file (the transaction file) by updating the clientTotal field in the client file according to the serviceTotal field i..

  Write down the syntax for a 2d array

Write the syntax for a 2D array which has four rows. The first row would have 10 elements and the second row will have 5 elements. The third row will have 8 elements and the fourth row will have 12 elements.

  Write down a public static method named chunk25

Write down a public static method named chunk25 that takes a double and returns an integer that represents the number of chunks of 25 in that number. A chunk of 25 is 25, or any part thereof

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd