Skip to content

Commit 4a2d7b1

Browse files
authored
Merge pull request #1 from okvarsh/okvarsh-patch-1
created DesignerPDFViewer.py
2 parents b4f454e + a6edaa4 commit 4a2d7b1

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

Problem Solving/DesignerPDFViewer.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'''
2+
When a contiguous block of text is selected in a PDF viewer, the selection is highlighted with a blue rectangle. In this PDF viewer, each word is highlighted independently.
3+
4+
There is a list of 26 character heights aligned by index to their letters. For example, 'a' is at index 0 and 'z' is at index 25. There will also be a string. Using the letter heights given, determine the area of the rectangle highlight in mm^2 assuming all letters are 1mm wide.
5+
6+
Example
7+
h=[1,3,1,3,1,4,1,3,2,5,5,5,5,1,1,5,5,1,5,2,5,5,5,5,5,5]
8+
word='torn'
9+
The heights are t=2, o=1, r=1 and n=1. The tallest letter is 1 high and there are 4 letters. The hightlighted area will be 2*4=8mm^2 so the answer is 8.
10+
11+
Function Description
12+
13+
Complete the designerPdfViewer function in the editor below.
14+
15+
designerPdfViewer has the following parameter(s):
16+
17+
int h[26]: the heights of each letter
18+
string word: a string
19+
20+
Returns
21+
22+
int: the size of the highlighted area
23+
24+
Input Format
25+
26+
The first line contains space-separated integers describing the respective heights of each consecutive lowercase English letter, ascii[a-z].
27+
The second line contains a single word consisting of lowercase English alphabetic letters.
28+
29+
Constraints
30+
31+
1<=h[?]<=7, where ? is an English lowercase letter.
32+
word contains no more than letters.
33+
34+
Sample input 0
35+
1 3 1 3 1 4 1 3 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
36+
abc
37+
38+
Sample output 0
39+
9
40+
41+
Explanation 0
42+
We are highlighting the word abc:
43+
44+
Letter heights are a=1, b=3 and c=1. The tallest letter, b, is 3mm high. The selection area for this word is 3*1*1=9mm^2.
45+
46+
Note: Recall that the width of each character is 1mm.
47+
48+
'''
49+
#!/bin/python3
50+
51+
# Complete the designerPdfViewer function below.
52+
def designerPdfViewer(h, word):
53+
ll=[]
54+
for el in word:
55+
ll.append(el)
56+
print(ll)
57+
asc=[]
58+
for i in range(len(ll)):
59+
print(ll[i]," ",ord(ll[i]))
60+
asc.append(ord(ll[i])-97)
61+
print(asc)
62+
chval=[]
63+
for elm in asc:
64+
chval.append(h[elm])
65+
print(chval)
66+
return len(word)*max(chval)
67+
68+
69+
if __name__ == '__main__':
70+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
71+
72+
h = list(map(int, input().rstrip().split()))
73+
74+
word = input()
75+
76+
result = designerPdfViewer(h, word)
77+
78+
fptr.write(str(result) + '\n')
79+
80+
fptr.close()

0 commit comments

Comments
 (0)