java, Computer Engineering

Assignment Help:
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 and Output

SNo. Input Output
1
2
aaab
aabbbc


4
2



Explanation:

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

Delete two a''s and add one ''b''. Total cost = 8
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

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

Related Discussions:- java

Digital electronics, Draw a circuit of an NMOS inverter and explain its ope...

Draw a circuit of an NMOS inverter and explain its operation

Polishing game, Byteland county is very famous for luminous jewels. Luminou...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Enumerate in brief about the intranet security policy, Enumerate in brief a...

Enumerate in brief about the Intranet security policy An Intranet security policy is a very broad topic and it cannot be covered easily in few pages since it differs from situa

What is pci bus, What is PCI bus? The Peripheral component interconnect...

What is PCI bus? The Peripheral component interconnect(PCI) bus is a standard that handles the functions found on a processor bus but in a standardized format that is independe

State some of the uses of ms access, MS Access provides a vast range of fun...

MS Access provides a vast range of functions some of them are ? It is used by small business, departments of large corporations, and by amateurs to make applications on their d

Define the refresh rates and frame rate, Q. Define the Refresh Rates and fr...

Q. Define the Refresh Rates and frame rate? A special circuit known as the Video Controller scans video memory one row at a time and reads data value at each address sending th

Data analysis and results in e-commerce, There were 50 respondents to our s...

There were 50 respondents to our survey. The first component of the data examined here focuses on student's preference (ecommerce or traditional commerce). The Second compone

Example of variables and quantifiers - first-order logic, Example of Variab...

Example of Variables and quantifiers: We should have started with something such which reflects the fact that we're really talking for some meal at the Red Lion, neverthe

Interrupt - driven input-output, Q. Interrupt - Driven Input-output? Pr...

Q. Interrupt - Driven Input-output? Problem with programmed I/O is that processor has to wait a long time for I/O interface to see whether a device is free or waits until compl

State about the internet services, State about the Internet services I...

State about the Internet services Internet services are provided automatically, in many other implementations the certificate is stored on a separate database or token such as

Write Your Message!

Captcha
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