0
0

More than 5 years have passed since last update.

第14回オフラインリアルタイムどう書くの参考問題 in python

Posted at

書いてみました。正直に言ってオフラインじゃないんですが(汗

sleeping_monsters.py
def parse(str):
    # count each letters
    return map(lambda x:ord(x) - ord('a'), list(str.lower()))

def test(in_str, answer):
    max = len("aBcDeFgHiJkL")-1
    xs = [parse(in_str).count(i) for i in range(max+1)]
    killed = 0
    idx = 0

    while idx < max:
        if xs[idx] != 0: # i got a weapon
            for monster in range(idx+1, max+1, 2) + range(1, idx, 2):
                if xs[monster] == 0:   # no monster here
                    break
                killed += xs[monster]  # found! kill monsters!
                xs[monster] = 0
                idx += 2
        idx += 2

    if killed != int(answer):
        print "failed! " + in_str + " expect: " + answer + " got: " + str(killed)
        exit()

test( "gLDLBgBgHDaD", "6" );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0