百度杯十一月Reverse03的checkflag代码

import sys

def debug():
    global a
    for i in range(0,9):
        for j in range(0,9):
            if a[i][j][0] == 0xFFEEFFEE:
                print '0',
            elif a[i][j][0] == 0xFEFEFEFE:
                print '1',
            elif a[i][j][0] == 0xEFEFEFEF:
                print '2',
            elif a[i][j][0] == 0xEEFFEEFF:
                print '3',
        print

def check():
    global a
    count = 0
    for i in range(0,9):
		for j in range(0,9):
			count = (count + a[i][j][0]) & 0xFFFFFFFF
    if count == 0xFC9CFC4D:
        return True
    else:
        return False

def init():
    global a
    for i in range(0,9):
        for j in range(0,9):
    		a[i][j][0] = 0xFFEEFFEE
    		a[i][j][2] = a[i][j][4] = 0xEFEFEFEF
    		if i == 0:
      			a[i][j][1] = 0xFEFEFEFE
    		else:
      			a[i][j][1] = 0xEFEFEFEF
    		if j == 0:
      			a[i][j][3] = 0xFEFEFEFE
    		else:
      			a[i][j][3] = 0xEFEFEFEF
    s = 'b1ngzl'
    for i in s:
        x = (ord(i) / 16) % 9
        y = (ord(i) % 16) % 9
        a[x][y][0] = 0xEEFFEEFF

def checkflag(s):
    global a
    global num
    length = len(s) ^ 4
    for i in range(length):
        x = (ord(s[i]) / 16) % 9
        y = (ord(s[i]) % 16) % 9
        if a[x][y][1] != 0xFEFEFEFE:
            a[x-1][y][0] = a[x-1][y][0] ^ 0x11111111
        if a[x][y][2] != 0xFEFEFEFE:
            a[x+1][y][0] = a[x-1][y][0] ^ 0x11111111
        if a[x][y][3] != 0xFEFEFEFE:
            a[x][y-1][0] = a[x-1][y][0] ^ 0x11111111
        if a[x][y][4] != 0xFEFEFEFE:
            a[x][y+1][0] = a[x-1][y][0] ^ 0x11111111
    if check() == True:
        print 'flag is right'
    else:
        print 'flag is wrong'

if __name__ == '__main__':
    a = [[[0] * 10 for i in range(10)] for j in range(10)]
    init()
    flag = '34567DEFG1234'
    checkflag(flag)
    debug()

全部评论

相关推荐

点赞 评论 收藏
分享
努力学习的小绵羊:我反倒觉得这种挺好的,给不到我想要的就别浪费大家时间了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务