标签:
STUART 的得分是以辅音字母开头的,KEVIN是以元音字母开头的,每有一个子字符串便的一分
笨办法是两重循环,内层循环去字符串中查找出现的次数,用一个字典存放已经查找过的子字符串。
O(n)的方法是:
# Enter your code here. Read input from STDIN. Print output to STDOUT s = raw_input() vowels = ‘AEIOU‘ kevsc = 0 stusc = 0 for i in range(len(s)): if s[i] in vowels: kevsc += (len(s)-i) else: stusc += (len(s)-i) if kevsc > stusc: print "Kevin", kevsc elif kevsc < stusc: print "Stuart", stusc else: print "Draw"
标签:
原文地址:http://www.cnblogs.com/rushyourmind/p/5185560.html