1. 60.multiplication

    a=89
    b=113
    print '%8d'%a
    print 'x%7d'%b
    c=b
    print '-'*8
    i=8
    while c>0:
        print '%*d'%(i,(c%10)*a)  # * means how many digit, i determines it
        c=c/10
        i-=1
    if i==7:                      # if b is 1 digit decimal, no more ------
        print ...
    read more
  2. 59. A square joining together

    # A square joining together
    class Solution(object):
        def removeoneside(self,nums,side):
            n=len(nums)
            res = [[0 for j in range(side + 1)] for i in range(n + 1)]
            # res[i][j] = max(res[i - 1][j],res[i-1][j-nums[i-1]]+nums[i-1])
            for i in range(1, n + 1 ...
    read more
  3. 55.In those years we collect cards

    # -*- coding: utf-8 -*-
    
    N=2
    b=float(N)
    a=0.0
    i=b
    while i > 0:
       a += N/i
       i -= 1
    print "%.2f" % a
    # 已经有n张卡片,得到下一张与手上不同的卡片的概率是N-n/N,期望是N/(N-n), 1+N/(N-1)+N/(N-2)+.......+N/(1)
    
    read more
  4. 53.The arrangement of the god

    # find if n*(n-1)/2 can be separated into two adjacent numbers
    def adjacent(num):
        a=round(num**(1/2.0),0)
        if a*(a+1)==num:
            return True
    
    god_num = 0
    for n in range(2,N+1):
        if adjacent(n*(n-1)/2):
            god_num+=1
            print n
    print(god_num ...
    read more
  5. 52.Factor sum of squares

    # -*- coding: utf-8 -*-
    
    # s = 0
    # for i in range(1,N+1):
    #   s = s + i**2*(N//i)    # step 1
    # print (s)
    
    # N = 16
    # L1 = list(range(1,N+1))
    # L2 = [N//i for i in L1]    # step 2 [16, 8, 5, 4, 3, 2, 2, 2, 1, 1, 1, 1 ...
    read more

« Page 15 / 21 »

blogroll

social