#coding=utf-8 import sys def min_change(str2):     #compare with "ABCABC"     str1 = "ABC"     res = []     result = 0     for i in range(0,len(str2)):         if str2[i]!=str1[i%3]:             result += 1     res.append(result)     #compare with "BCABC"     result = 0     for i in range(0,len(str2)):         if str2[i]!=str1[(i+1)%3]:             result += 1     res.append(result)     #compare with "CABCABC"     result = 0     for i in range(0,len(str2)):         if str2[i]!=str1[(i+2)%3]:             result += 1     res.append(result)     return min(res) def change(n,k,substr):     res = []     for i in range(0,n-k+1):         res.append(min_change(substr[i:i+k]))     return min(res)              if __name__ == "__main__":     loop = int(sys.stdin.readline().strip())     ans = 0     res = []     for i in range(loop):         line = sys.stdin.readline().strip()         substr = sys.stdin.readline().strip()         n,k = map(int,line.split())         res.append(change(n,k,substr))     for i in range(loop):         print res[i]
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务