TopCoder problem "FontSize" used in SRM 265 (Division II Level One)



Problem Statement

    Graphical user interfaces rely on text routines to properly display words on various GUI components. Being able to determine the width in pixels of a line of text is useful for centering the text in a window. You will be given a sentence of letters and spaces. You will also be given the letter widths for both uppercase and lowercase letters of a particular font. You must return the width of the sentence.

Both uppercase and lowercase contain 26 elements. The first element of uppercase is the width of 'A' and the last is the width of 'Z'. The first element of lowercase is the width of 'a' and the last is the width of 'z'. The width of the space character is always 3 pixels. When a line of text is rendered, there is a gap of 1 pixel between each pair of adjacent characters.

 

Definition

    
Class:FontSize
Method:getPixelWidth
Parameters:String, int[], int[]
Returns:int
Method signature:int getPixelWidth(String sentence, int[] uppercase, int[] lowercase)
(be sure your method is public)
    
 

Constraints

-sentence will contain between 1 and 50 characters, inclusive.
-sentence will only contain uppercase letters ('A'-'Z'), lowercase letters ('a'-'z'), and spaces.
-uppercase will contain exactly 26 elements.
-lowercase will contain exactly 26 elements.
-Each value in uppercase and lowercase will be between 1 and 36, inclusive.
 

Examples

0)
    
"Dead Beef"
{6,6,6,7,7,7,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
{5,5,5,4,4,4,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
Returns: 49
D   e   a   d  (space)  B   e   e   f
7+1+4+1+5+1+4+1 + 3 + 1+6+1+4+1+4+1+4 = 49
1)
    
"Hello World"
{7,8,8,8,7,8,8,8,7,8,8,8,8,8,7,8,8,8,8,8,7,8,8,8,8,8}
{5,6,6,6,5,6,6,6,5,6,6,6,6,6,5,6,6,6,6,6,5,6,6,6,6,6}
Returns: 74
2)
    
"Hello World"
{7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,9,7,7,7}
{5,5,5,6,6,5,5,5,5,5,5,1,5,5,6,5,5,6,5,5,5,5,5,5,5,5}
Returns: 63
3)
    
"ThE qUiCk BrOwN fOx JuMpEd OvEr ThE lAzY dOg"
{36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11}
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
Returns: 778
4)
    
"two  spaces"
{9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
Returns: 43

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2000

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8007&pm=2000

Writer:

HardCoder

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration