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

  How to maintain different document object models

Both the Netscape/Mozilla and IE browsers maintain different document object models. Given the current era of open source, what do you think is the wisdom of maintaining two models.

  Advantages and drawbacks of electronic business

Electronic business (e-business) is the conduct of commercial transactions with the help of telecommunications. Among the benefits of e-business are a global marketplace. Name other advantages and drawbacks.

  Write down a user-defined function

Write down a user-defined function

  How to use control flow to track membership

Using the Internet and other resources, discuss and study "control flow" in programming. How would you use control flow in computer programming to solve problems? Give an example of how you would use control flow to track membership dues in a smal..

  What is the sql

Recently AMI has been experiencing significant downtime because of  a failing software application written for AMI when the company started. This Access database application is responsible for a main manufacturing process.

  Recognize what stuffed animals were bought

recognize what stuffed animals were bought before the year 2000. Advise her regarding how she can accomplish these tasks.

  Define beneficial for certain types of projects

There is a school of thought that argues that, far from being undesirable, some degree of scope creep may in fact be beneficial for certain kinds of projects e.g. it encourages stakeholder engagement, indicates responsiveness, and shows that objec..

  Disadvantages of using multiple models

offer two common failures in moving a system from development into production status.

  How to modify the temperature conversion program

Add two buttons to temperature conversion program. Clicking one button converts Fahrenheit to Celsius, clicking the other converts Celsius to Fahrenheit. It will help the user to have a "clear" button that clears  text in both text fields.

  Bus collision avoidance protocol

Before effective Ethernet switching existed, some network designers are used an alternative bus collision avoidance protocol termed as the token bus protocol.

  What are the object-oriented and structured designs

explain the architectural differences between the object-oriented and structured designs.

  Create an xml document containing information

Create an XML document containing information.

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