Super ASCII String Cost, C/C++ Programming

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:- Super ASCII String Cost

What are the debugging methods you employ while came across , What are the ...

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

How do you know that your class requires virtual destructor, How do you kn...

How do you know that your class requires a virtual destructor? A: If at least your class has one virtual function, you must make a destructor for this class virtual. It will let

Super ASCII String Cost, A string S is said to be "Super ASCII", if it cont...

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 asci

Standard input- output using motorola and intel devices, Talking to IO boar...

Talking to IO boards inside a computer or microcontroller depends upon the principles used by the microprocessor to address physical devices. On Motorola systems all devices connec

Quick sort , Hi, I need quick sort program without using recursion

Hi, I need quick sort program without using recursion

Purchasing code signing certificate, Purchasing Code Signing Certificate ...

Purchasing Code Signing Certificate I want to purchase a Code Signing Certificate in good standing from someone in order to sign my .EXE programs with. Please be aware I do n

Explain structured programming, Explain structured programming The prin...

Explain structured programming The principal idea behind structured programming was as easy as the idea of "divide and conquer." A computer program could be regarded as having

Explain the bit fields portable or not, Explain the  bit fields portable o...

Explain the  bit fields portable or not? - No, Bit fields aren't portable. - As Bit fields can't span machine words and number of bits in a machine word is different on diff

We want network-social app, We are seeking a talented developer/team with g...

We are seeking a talented developer/team with great experience in programming apps for both Android and iOS. Our project needs great skills and experience in making good functional

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