1 def main(): 2 3 t = int(raw_input()) 4 5 for _ in xrange(t): 6 s = raw_input().strip() 7 s_len = len(s) 8 is_funny = True 9 for i in xrange(1, len(s)/2+1): # 比较一半儿就行了,因为是对称的 10 if abs(abs(ord(s[i])-ord(s[i-1]))) != abs(ord(s[s_len-1-i])-ord(s[s_len-i])): 11 is_funny = False 12 break 13 14 if is_funny: 15 print "Funny" 16 else: 17 print "Not Funny" 18 19 main()
Link:
https://www.hackerrank.com/challenges/funny-string
学习:
比较一半
中心对称的字符串
时间: 2024-11-10 17:13:56