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

What are the standard types of files produced, What are the standard types ...

What are the standard types of files produced? A PDF file is universally recognized by the internet and is also a secure image, given that an electronic footprint remains when

Explain the following the address instruction, Explain the following the ad...

Explain the following the address instruction?  Three-address instruction-it can be represented as add a,b,c Two-address instruction-it can be shown as Add a,b

What are the properties of electronic cash, What are the properties of elec...

What are the properties of electronic cash? Properties: 1. Monetary Value: Monetary value should be backed by bank certified cashier’s cheque or cash, bank authorized cred

Logical drives is it possible to fit onto a physical disk, How many logical...

How many logical drives is it possible to fit onto a physical disk? Ans) Maximum of 24 logical drives can be fit into physical disk. The extended partition can only have 23 lo

Existential introduction, Existential Introduction: Now if we have any...

Existential Introduction: Now if we have any sentence as, A, and variable, v, that does not occur in A, so then for any ground term, g, such occurs in A, than we can turn A in

What is the difference between intranet and extranet, What is the differenc...

What is the difference between intranet and extranet? Given table illustrates brief overview of the differences among the three kinds of the network: Network

Define hyperlinks, Q. Define Hyperlinks? Hyperlinks, or links are one o...

Q. Define Hyperlinks? Hyperlinks, or links are one of the most significant characteristics of web pages. A link moves us from current page to a destination which is specified i

Shm, composition of two shm in right angles to each other to havingg time p...

composition of two shm in right angles to each other to havingg time period in the ratio 1:2

Draw the logic circuit of Decimal to BCDencoder, What is an encoder? Draw t...

What is an encoder? Draw the logic circuit of Decimal to BCD encoder and explain its working. Ans. Encoder: It is a combinational logic circuit which converts alphanumeric ch

Logic gates required to build a half adder, What are the gates required to ...

What are the gates required to build a half adder ? Ans. The gates needed to build a half adder are EX-OR gate and AND gate as shown below the logic diagram of half adder:

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