输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000。
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
zoj ozojo ozoojoo oozoojoooo zooj ozojo oooozojo zojoooo
Accepted Accepted Accepted Accepted Accepted Accepted Wrong Answer Wrong Answer
#Python的简单实现,这里排版那么好看,就参考一下嘛:
#将ZOJ中的O转换成数字来查找是否满足条件 def findWhetherZOJ(leftNum,midNum,rightNum): if midNum==1: #如果中间O的个数为1时左右O的个数必须相等(条件1和条件2) if leftNum==rightNum: return True else: return False elif midNum <= 0: #如果中间O的个数为0则为输出错误 return False else: #递归查找是否满足(条件3),条件3的结论和前提比较右边的O个数多一倍左边的个数,中间的O个数多一 return findWhetherZOJ(leftNum,midNum-1,rightNum-leftNum) while True: try: string = input() #剔除一些错误条件(Z和J必须为一个,剩余必须都为O,Z必须在J的前面) if string.count('z') != 1 or string.count('j') != 1 or string.count('o')+2 != len(string) or string.index('z')>string.index('j'): result = False else: leftNum = len(string[:string.index('z')]) #得到左边O的个数 rightNum = len(string[string.index('j')+1:]) #得到右边O的个数 midNum = len(string)-leftNum-rightNum-2 #得到中间O的个数 result = findWhetherZOJ(leftNum,midNum,rightNum) if result: print('Accepted') else: print('Wrong Answer') except Exception: break