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

Protocols and services on internet, To work with Internet as well as to uti...

To work with Internet as well as to utilize its facilities we use certain tools. For illustration, Telnet is a tool, which is utilized for logging on remote computers on the Intern

Explain design parameters, Explain the following design parameters S, ...

Explain the following design parameters S, SC, TC, C, CCI, EUF, K, T S The various terms are given below: S: Total number of switching components A good design sh

Explain working of d flip -flop, Q. Explain working of D Flip -Flop? D ...

Q. Explain working of D Flip -Flop? D (data) flip-flop is modification of RS flip-flop. Problem of undefined output in SR flip-flop when both R and S become 1 gets avoided in D

What are the features of abap/4 dictionary, What are the features of ABAP/4...

What are the features of ABAP/4 Dictionary? The most significant features are: Integrated to aABAP/4 Development Workbench. Active in the runtime environment.

Where traffic intensity can be measured, Traffic Intensity can be measured ...

Traffic Intensity can be measured in (A)  Erlangs                                    (B) CCS (C)  CM                                         (D) All of the above Ans:

Define the term grade of service, Define the term Grade of Service. Gr...

Define the term Grade of Service. Grade of Service: In loss systems, the traffic carried through the network is usually lower than the actual traffic offered to the network t

What is meant by Wired-AND connection of digital ICs, What is meant by Wire...

What is meant by Wired-AND connection of digital ICs?                                                                                                               Ans: Wir

By which the speech of side tone is heard, Side tone is the speech heard by...

Side tone is the speech heard by (A)  the receiving subscriber (B)  both the receiving and calling subscriber (C) by on looker (D) by calling subscriber Ans

Determine the return loss and round trip delay for echo, In a national tran...

In a national transmission system, the characteristic impedances of the 4-wire circuit and the 2-wire circuit are 1200 ? and 1000 ? respectively. The average phase velocity of the

Connectivity options accessible to internet subscribers, What are the diffe...

What are the different connectivity options accessible to Internet Subscribers? Explain in detail. Internet Connectivity Options: Internet access is perhaps one of the ma

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