1. 27.Gas Station

    limit = [1,2,3,4]
    cost = [4,2,1,3]
    
    sum = 0
    subsum = 0
    ix = 0
    for i in range(len(limit)):
        delta = limit[i] - cost[i]
        sum += delta
        subsum += delta
    
        if subsum < 0:
            ix = i + 1
            subsum = 0
    
    if sum<0:
        print -1
    else:
        print ix
    
    read more
  2. 25.Format the time

    t={'year':'2013','month':'9','day':'30','hour':'16','minute':'45','second':'2'}
    print '%04d-%02d-%02d %02d:%02d:%02d' %(int(t['year']), int(t['month']), int(t['day']), int(t['hour']), int(t['minute']), int(t['second']))
    
    read more
  3. 24.Horse take the lead

    m=2
    n=1
    
    if m < n:
        m, n = n, m
    
    horse = [(1, 2), (2, 1), (-1, 2), (-2, 1), (-2,-1),(-1,-2),(1, -2), (2, -1)]
    queue = [(0, 0)]
    goal = {(0, 0): 0}
    
    while queue != []:
        base = queue.pop(0)
    
        for item in horse:
            arrow = ((item[0] + base[0 ...
    read more
  4. 22.Time is money

    st="00:00:00"
    et="00:00:10"
    
    print abs(int(st.split(':')[0])*3600 + int(st.split(':')[1])*60 + int(st.split(':')[2])-(int(et.split(':')[0])*3600 + int(et.split(':')[1])*60 + int(et.split(':')[2])))
    
    read more

« Page 18 / 21 »

blogroll

social