Deft written test (to be more unfinished)

Title Description
find an array subscript all the following conditions of the elements: one and only one of its large front element this element. If no such element exists outputs -1. The time requirements of the algorithm complexity is O (n)
sample a
1,222,233,221,245,445
. 4. 7
Sample two
. 1 22 is 54 is 123
-1

solution:

l = list(map(int, input().split()))
res, firstmax, secondmax = [], 0, 0
for i in range(len(l)):
    if l[i] > firstmax:
        secondmax = firstmax
        firstmax = l[i]
    else:
        if l[i] == firstmax:
            secondmax = l[i]
        else:
            if secondmax <= l[i]:
                secondmax =l[i]
                res.append(i)
print(" ".join(map(str, res)) if res else -1)

Title Description
8 the phone number, if there are more than three and three consecutive identical digits or numbers, such as 123 (called straight), 666 (called leopard), Liang number is called. Liang Each has its own value, in accordance with the output value of the size of each sort of Liang (descending), the value of evaluation of Rule follows:
more 1) bits larger value
2) is greater than with straight-digit leopard
3) are straight while taking leopards maximum value
4) the value of the same phone number the output order in an input order
if there is no Liang, the null output
sample a
15112347234,15176313245,15176313346,15176313325,15166667234,15188847234
15166667234,15112347234 , 15188847234
sample two
14612244221,14612544221,14612644221
null

Solution:
made for each phone number entered trip traversal satisfying the condition is extracted leopard, straight substring, and then calculate the maximum length of the substring, if the same length of the substring, leopard imparting a flag, flag bit 0 imparting straight

l = list(input().split(','))
res = []
for i in range(len(l)):
    tmp = []
    for j in l[i][3:]:
        tmp.append(int(j))
    baozi, shunzi, l_baozi, l_shunzi, j = "", "", [], [], 0
    while j < 7:
        if tmp[j] + 1 == tmp[j+1]:
            k = j + 1
            while k < 7:
                if tmp[k] + 1 == tmp[k +1]: k += 1
                else: break
            shunzi = "".join(map(str, tmp[j:k + 1]))
            if len(shunzi) >= 3: l_shunzi.append(shunzi)
            shunzi = ""
            j = k
        elif tmp[j] == tmp[j + 1]:
            

            k = j + 1
            while k < 7:
                if tmp[k] == tmp[k+1]: k+=1
                else: break
            baozi = "".join(map(str, tmp[j:k + 1]))
            if len(baozi) >=3: l_baozi.append(baozi)
            j = k
        else:
            j += 1
    mmax_shunzi = max(len(i) for i in l_shunzi) if l_shunzi else 0
    mmax_baozi = max(len(i) for i in l_baozi) if l_baozi else 0
    if mmax_shunzi == 0 and mmax_baozi == 0:
        continue 
    if mmax_baozi >= mmax_shunzi:
        res.append((l[i], mmax_baozi, 1))
    else:
        res.append((l[i], mmax_shunzi, 0))
if res:
    res.sort(key = lambda x: (x[1], [2]))
    for i in range(len(res) - 1, -1, -1):
        print(res[i][0])
else:
    print("null")

Description Title
has a board, a top unit is marked with a corresponding energy value, to put the chip on the board (the board and the chip are rectangular, not necessarily square). Discharge device has the following rules:
1) the energy in the region covered with the chip to the same value, if they have the same release of energy, the energy freed several units, the cost of the chip is mounted on the number
2) If there are a plurality of minimum cost installation position, in accordance with the row minimum row as in accordance with the column minimum
3) If there are no mounting position at the current price, then find the location of secondary cost for installation, until the board able to install
input:
mnab (MXN board size, AXB chip size)
MXN matrix representation of each of the unit energy values
output
xy cost (chip mounting position of the upper left corner of the cell occupied positions, starting at 1, the cost of the chip mounting)
sample an
input
2 2 2 1
2 1
31
output
2
. 1 0 2
. 1. 1. 1
sample two
inputs
. 4. 5 2. 3
. 1. 4. 9. 7. 8
. 7 2 2. 4. 5
. 6. 7. 8. 9. 3
. 4. 5. 6. 5 2
output
2
. 3 2 10
. 1 16. 3

Published 152 original articles · won praise 22 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_38204302/article/details/105048218