Print the minimum cost of conversion for each string

Assignment Help Programming Languages
Reference no: EM131136103

Problem:

Super ASCII String Cost A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets ('a'-'z') and the ascii values will starts from 1 (i.e ascii value of 'a' is 1 and 'z' is 26). Now given a string S, you can perform operations, namely, add, delete and replace of any character present in the string. Every operation will consists of following costs

add = 2 unit
replace = 1 unit
delete = 3 unit

Your task is to convert the string to super ascii with the minimum cost. While converting the string to super ascii, the final string should contain the same characters as in the input string.

Input Format:

First line starts with T i.e. number of test cases, and then T lines will follow each containing a string "S".

Output Format:

Print the minimum cost of conversion for each string to a Super Ascii string.

Constraints:

1<=T<=100 1<=|S|<=300, S will contains only lower case alphabets ('a'-'z').

sample input

2
aaab
aabbbc

sample output

4
2

Explanation:

For Case1:

Need to retain a, b since these are unique characters in this string

Some of possible ways are

1. Delete two a's and add one 'b'. Total cost = 8

2. Replace one a with b, and delete other 'a'. Total cost = 4.

For Case2:

Need to retain a, b, c since these are unique characters in this string Some of possible ways are

1. Replace 'a' and 'b' with 'c'. Total cost = 2.

2. Delete one 'a' and one 'b' and then add two c's. Total cost = 10.

Note:
Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.

Reference no: EM131136103

Questions Cloud

Tenants with rights of survivorship : Brian and Scott own a house as joint tenants with rights of survivorship. Brian sold his half interest to Brad. Shortly thereafter, Scott died, and Brad claimed the entire property by survivorship. Was Brad legally entitled to it? Explain.
Why samsung is facing lots of global mobile market challenge : why Samsung is facing lots' of global mobile market challenges.- Conduct a detailed research analysis of the reasons.
What insight does this give you into the company financial : Determine the current assets to total assets ratio for the construction company in Figures 6-1 and 6-2. What insight does this give you into the company's financial operations?
How the technology information applies to global environment : Write a 2- to 3-page paper explaining how this technology information applies to the global environment. Include details of how the global environment changes what is utilized in the local environment.
Print the minimum cost of conversion for each string : Print the minimum cost of conversion for each string to a Super Ascii string - Your task is to convert the string to super ascii with the minimum cost. While converting the string to super ascii, the final string should contain the same characters ..
Why are special legislative sessions called : Why are special legislative sessions called? What are the consequences of the governor calling special sessions -- for the legislators, and for the governor
Find five recent examples of alleged wasteful expenditures : Explain how a Federally funded project might be wasteful from a national perspective, yet still be highly beneficial for a specific city or state.
Is mr gates acquisition of additional wealth fair : Using the "it's not fair if the rules aren't fair" approach to fairness, is Mr. Gates' acquisition of additional wealth fair? Is the (poor) thief's acquisition fair?
Where the media has unfairly portrayed : Public officials try to use the media to set the public agenda, resulting in public opinion about those issues cohering to public officials' intentions. Can you think of an instance where the media has unfairly portrayed a government official's act..

Reviews

Write a Review

Programming Languages Questions & Answers

  Create a program that asks the user for the values of x and

in engineering thermodynamics it is sometimes necessary to balance chemical reaction equations specifically for the

  Program to design a decision structure and a loop structure

A palindrome is a word or phrase that reads the same forwards and backwards, character for character, disregarding punctuation, case and spaces

  Determine average cpi for program for clock cycle time

The table above illustrates the execution time of two different compiled programs. Determine the average CPI for each program given that processor has clock cycle time of 1 nS.

  Compute the area of a circle

In MIPS assembly, write an assembly language program which asks a user for a decimal number, converts it to hex, prints the result.

  Create a program that uses the same formula

Create a program that uses the same formula above to output the result; this time, however, prompt the user for the values a, b, x, and y.

  Test a program for summing

You are to implement and test a program for summing 1/x as x runs over all approximately eight million (23 fraction bits) single precision floating point numbers in the interval [1, 2). You are to do this on a server, PC (or Mac) of your choice..

  Write a program to show simplified bill

Write a program to show a simplified bill. Customers name, number of hours of labor, and cost of parts and supplies must be entered into program via text boxes.

  Write program for real estate agent

Write a program for a real estate agent. The program should perform the following tasks: ask users for the average house price for the each of past 5 years for a single family residence of 1500 square feet.

  Write a perl program that performs show current date

Write a Perl program that performs the following tasks: Generate a menu to ask the user for the task that he or she would like to see performed. The available tasks are as follows: Show current date and time

  Create a logical expression

Create a logical expression that corresponds to the following statement - Complete the truth table for the expression created.

  Proc mean data=ex1height

Proc mean data=EX1height;throws what sort of error message

  The ideal hpc programming language

Read the article titled, "The Ideal HPC Programming Language" dated 2010. Article Source: Loh, E. (2010, June). The ideal hpc programming language

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