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

Advantages of instruction set architecture, Advantages of Instruction set a...

Advantages of Instruction set architecture: Stack Advantages : it is simple Model of expression evaluation (reverse polish). Contain Short instructions. Disadvanta

Simplify the expressions using boolean postulates, Simplify the given expre...

Simplify the given expressions using Boolean postulates XY + X‾Z‾  + XY‾Z (XY + Z) Ans. XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾  + XXYY‾Z

Briefly explain array processing in detail, Array Processing We have se...

Array Processing We have seen that for executing vector operations the pipelining conception has been used. There is other method for vector operations. If we have array of n p

Explain the process of skolemization., Problem 1. Explain briefly the p...

Problem 1. Explain briefly the process of matching production rules against working memory 2. What are the different kinds of knowledge that need to be represented in AI? Ex

Challenges in changing information technology, Q: Challenges and Prospects ...

Q: Challenges and Prospects in Changing Information Technology? There is no doubt that information technology has made significant progress during the past two decades. Modern

Determine the importance of computer hardware, Determine the importance of ...

Determine the importance of computer Hardware Hardware forms the greatest asset of the company, but it reaches obsolescence very quickly. Normally, it is said that every six mo

What is arithmetic pipeline, What is arithmetic pipeline?  Pipeline ari...

What is arithmetic pipeline?  Pipeline arithmetic units are usually found in very high speed computers. They are used to execute floating point operations, multiplication of fi

What are the basic components of an expert system, Q. What are the basic co...

Q. What are the basic components of an expert system? ANSWER: There are three components of components: Information, people, and IT components. Information kinds are domain exp

Explain protection mechanism, Explain Protection mechanism. Protection...

Explain Protection mechanism. Protection mechanism: The subsequent mechanisms are commonly utilized for protecting files having programs and data. (a) Access controls list

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