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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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