求助一道CSP的一道题,不知道哪里错了
题目内容如下,这道题中前景色没啥用,主要是背景色起了作用。
我自己写完之后跑了网上很多测试数据,结果都一样,但是一提交显示答案错误,0分,很是郁闷,不知道自己哪里没有想到。希望大佬可以帮我看看代码,看看我哪个点没想到。
代码
def deal_format(pic): if len(pic)==6: return (int(pic[0:2],16),int(pic[2:4],16),int(pic[4:6],16)) elif len(pic)==1: return (int(pic*2,16),int(pic*2,16),int(pic*2,16)) else: return (int(pic[0:1]*2,16),int(pic[1:2]*2,16),int(pic[2:3]*2,16)) def solve_avg(pic): rlt = [] for p in pic: r = [] g = [] b = [] for j in range(len(p)): r.append(p[j][0]) g.append(p[j][1]) b.append(p[j][2]) rlt.append([sum(r)//len(r),sum(g)//len(g),sum(b)//len(b)]) return rlt def print_hex(s): raw = "\\x1B\\x5B\\x34\\x38\\x3B\\x32\\x3B{}\\x3B{}\\x3B{}\\x6D\\x20" s = list(map(str,s)) rlt = [] for num in s: tmp = '' for j in num: tmp+='\\x'+hex(ord(j))[2:] rlt.append(tmp) return raw.format(rlt[0],rlt[1],rlt[2]) reset = "\\x1B\\x5B\\x30\\x6D"#重置 current = [0,0,0] #get m,n m,n = map(int,input().split()) #get p,q p,q = map(int,input().split()) #input the pic pic = [[] for _ in range(n)] for i in range(n): for j in range(m): tmp = input()[1:] pic[i].append(tmp) split_pic = [] #分割 归属于同一块的放到一个列表中 for i in range(n//q): for j in range(m//p): tmp = [] for k in range(q): for l in range(p): tmp.append(deal_format(pic[k+i*q][l+j*p])) split_pic.append(tmp) avg = solve_avg(split_pic) count = 0 for i in range(len(avg)): if avg[i]!=current: current = avg[i] if current==[0,0,0]: print(reset,end='') else: print(print_hex(current),end='') else: print('\\x20',end='') count+=1 #扫描完了一整行 if count%(m//p)==0: if current!=[0,0,0]: print(reset,end='') current = [0,0,0] print('\\x0A',end='')
测试数据
https://blog.csdn.net/qhy6518338/article/details/102827947
#悬赏##笔试题目##Python#