• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Not understanding a programming question.

JC0133

Senior member
Programming Challenge:

Given a string s, compute the sum, each letter is an integer between 1 and 26, inclusive, and no two letters have the same value. (Uppercase 'F' is exactly as as lowercase 'f', for example.)

You're a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible of this string?

Input:
Your program should read lines from standard input. Each line is a string.
Output:
Print out the maximum for the string.
Test 1
Test Input

ABbCcc
Expected Output

152
Test 2
Test Input

Ignore punctuation, please
Expected Output

491

I don't understand how they are getting the value for each letter. I originally thought if A = 1 and B = 1 then the sum would be 1 + 2 + 2 + 3 + 3 +3 but that is not 152. Then I thought maybe use the asc ii values of characters but then a and A would not be the same and either way it is much higher then 152.

So can anybody give me any hints about this problem??
 
I think the idea is you consider each letter as a variable. Consider the string as the sum of the variables listed in it. Assign the 26 variables unique values between 1 and 26 such that the sum is maximized.

So for "abbccc", it's best to set c=26, b=25, a=24, and we don't care about the rest. Then the sum is 24+25+25+26+26+26 = 152.
 
This is more of an algebra problem rather than a programming problem.

The answer is 17 of the letter c, 1 of letter b, 1 of letter a.

I think you're getting tripped up on figuring out the rest of the letters in the alphabet as a number, which you don't need to. The question didn't specify that at all.
 
I think the idea is you consider each letter as a variable. Consider the string as the sum of the variables listed in it. Assign the 26 variables unique values between 1 and 26 such that the sum is maximized.

So for "abbccc", it's best to set c=26, b=25, a=24, and we don't care about the rest. Then the sum is 24+25+25+26+26+26 = 152.
Jesus if that is really what the problem is asking, it was very poorly worded and had very poor explanation in the test input/output. Your explanation makes sense though. It's pretty easy/straight forward after realizing that as far as a solution goes too.
 
Thanks this helped me a lot guys. I think trying to figure out every value for each letter was my problem.
 
Back
Top