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
59. A square joining together
read more# 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 ...
58.The least common multiple I
read moreL=[2,8,3,50] s=sorted(L) min=s[-1] max=s[0] for i in range(1,len(s)): max=max*s[i] lcm=min for m in range(max,min,-1): for i in range(len(s)): if m%s[i]==0 and i!=len(s)-1 ...
57.Change the position
read moren=2 if n%2: print (n-1)**2/4 else: print n*(n-2)/4
56.Cut the watermelon
read moren=3 print int((n ** 3 + 5 * n + 6) / 6)
55.In those years we collect cards
read more# -*- 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)
54.Back to the longest text string is not simple
read moreL = "caayyhheehhbbbhhjhhyyaac" start, length = 0, 0 for i in range(1,len(L)-1): if L[i] == L[i+1]: s = min(len(L[:i+1]),len(L[i+1:])) a, b = 1, 1 while a < s: if L[i-a] == L[i+1+a]: # to the left 1 pace ...
53.The arrangement of the god
read more# 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 ...
52.Factor sum of squares
read more# -*- 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 ...
51.Descending order
read moreL = [2, 8, 3, 50] print sorted(L)[::-1] print [x for x in reversed(sorted(L))]