Facebook Hacker Cup 2012 Alphabet Soup Problem
#!/usr/bin/python noi=input('how many string you wanna check :').strip('\r') noi=int(noi) finale=[] for we in range(1,noi+1): inp=input('enter the string: ').strip('\r') list=inp.split(' ') ty='' for x in list: ty+=x lis=[] for x in ty: lis.append(x) if lis[len(lis)-1]=='\n': lis=lis[:-1] h=[] a=[] c=[] k=[] e=[] r=[] u=[] p=[] for x in 'HACKERUP': first=-1 try: while first < (len(ty)-1): first=ty.index(x,first+1) if x=='H': h.append(x) elif x=='A': a.append(x) elif x=='C': c.append(x) elif x=='K': k.append(x) elif x=='E': e.append(x) elif x=='R': r.append(x) elif x=='U': u.append(x) elif x=='P': p.append(x) except ValueError: continue if len(c)%2==0: c=c[0:int(len(c)/2)] elif len(c)%2!=0: c=c[0:-1] c=c[0:int(len(c)/2)] ans=min(len(h),len(a),len(c),len(k),len(e),len(r),len(u),len(p)) res='Case #' res+=str(we)+': ' res+=str(ans) finale.append(res) for x in finale: print(x)