The problem is from codeforces: http://www.codeforces.com/problemset/problem/262/A
#!/usr/bin/env python n, k = map(int, raw_input().split()) s = raw_input().split() ans = 0 for x in s: ans += 1 if x.count('4') + x.count('7') <= k else 0 print ans
Or a much shorter version.
N,K=map(int,raw_input().split()) print sum(i.count('4')+i.count('7')<=K for i in raw_input().split())
However, during the online contest, I wrote the solution in standard way, not using any benefits of Python programming language.
#!/usr/bin/env python n, k = map(int, raw_input().split()) s = raw_input().split() ans = 0 for x in s: j = 0 for i in xrange(len(x)): t = x[i] if (t == '4') or (t == '7'): j += 1 if (j > k): break if j <= k: ans += 1 print ans
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
229 wordsloading...
Last Post: CSS for Image onmouseover Event
Next Post: Codeforces: B. Roma and Changing Signs