Connection Status:
Competition Arena > FontSize
SRM 265 · 2005-09-27 · by HardCoder · Simple Search, Iteration
Class Name: FontSize
Return Type: int
Method Name: getPixelWidth
Arg Types: (string, vector<int>, vector<int>)
Problem Statement

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.

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)
"   WWW   lll   MMM   iii   "
{9,9,9,9,9,9,9,9,9,9,9,9,36,9,9,9,9,9,9,9,9,9,36,9,9,9}
{9,9,9,9,9,9,9,9,1,9,9,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
Returns: 293

Submissions are judged against all 50 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FontSize with a public method int getPixelWidth(string sentence, vector<int> uppercase, vector<int> lowercase) · 50 test cases · 2 s / 256 MB per case

Submitting as anonymous