The problem is from codeforces: http://www.codeforces.com/problemset/problem/96/A
The problem is another easy one. It asks you to check if there are more than 7 players that belong to the same team standing together. Two teams are denoted as ‘1’, ‘0’ respectively. It is easier to set a flag in the beginning or at the end, which prevents the range check for the array. For example, by setting a flag ‘X’ at the beginning, you can count if the current team member is the same as its previous one. If yes, increment the counter (and compare to the current best one, if it is bigger than the current best, replace the counter). If the team member is different, clear the counter to 1 and continue to the next loop.
Python solution, as usual, gives an accepted answer within a few lines of code. (This is another problem that I got it accepted within a minute).
s = raw_input() l = "x" s = l + s m = 1 k = 1 for i in s: if i == l: k += 1 if k > m: m = k else: l = i k = 1 if m >= 7: print "YES" else: print "NO"
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Copy by reference or value in Python
Next Post: Which.bat for windows command shell