import string
def typist(words):
tag=0
num=len(words)
if words[0] in string.ascii_uppercase:
num=num+1
tag=0
else:
tag=1
for i in range(1,len(words)):
if words[i] in string.ascii_lowercase and tag==0:
tag=1
num=num+1
if words[i] in string.ascii_uppercase and tag==1:
tag=0
num=num+1
print(num)
return num
def typist(words: str) -> int:
result = 0
caps_lock = False
for word in words:
if (word.isupper() and not caps_lock) or (not word.isupper() and caps_lock):
result += 1
caps_lock = not caps_lock
result += 1
return result
assert typist("aA") == 3
assert typist("Aa") == 4
assert typist("AAAaaaBBBbbbABAB") == 21
def typist(words: str) -> int:
sum = 0
for i in range(len(words)):
# 如果第i位是小写字母
# 如果第i-1位是小写字母或者第i位是第一位,键盘次数+1
# 否则第i-1位是大写字母,键盘次数+2
if words[i].islower():
if words[i - 1].islower() or i == 0:
sum += 1
else:
sum += 2
# 如果第i位是大写字母
# 如果第i-1位是小写字母或者第i位是第一位,键盘次数+2
# 否则第i-1位是大写字母,键盘次数+1
else:
if words[i - 1].islower() or i == 0:
sum += 2
else:
sum += 1
return sum
def typist(words: str) -> int:
l = [str(int(w == w.upper())) for w in words]
upper_areas = len([i for i in str("".join(l)).split('0') if i!=""])
return upper_areas*2 + len(words) - (1 if l[len(l)-1]=='1' else 0)