aboutsummaryrefslogtreecommitdiff
path: root/challenge-267/eric-cheung/python/ch-2.py
blob: 813851dabbf5cb913aa816d0ff7a77e0e04e27e6 (plain)
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
27
28
29
## Example 1
## strInput = "abcdefghijklmnopqrstuvwxyz"
## arrCharWidth = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]

## Example 2
strInput = "bbbcccdddaaa"
arrCharWidth = [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]


nMaxUnitPerLine = 100

arrLineOutput = []
nLineUnitCount = 0
strLineAppend = ""

for charLoop in strInput:
    nIndx = ord(charLoop) - ord("a")
    if nLineUnitCount + arrCharWidth[nIndx] > nMaxUnitPerLine:
        arrLineOutput.append(strLineAppend)
        nLineUnitCount = 0
        strLineAppend = ""

    strLineAppend = strLineAppend + charLoop
    nLineUnitCount = nLineUnitCount + arrCharWidth[nIndx]

arrLineOutput.append(strLineAppend)

print ([len(arrLineOutput), nLineUnitCount])