找出给定字符串中大写字符(即'A'-'Z')的个数。
数据范围:字符串长度:
字符串中可能包含空格或其他字符
进阶:时间复杂度:,空间复杂度:
对于每组样例,输入一行,代表待统计的字符串
输出一个整数,代表字符串中大写字母的个数
A 1 0 1 1150175017(&^%&$vabovbaoadd 123#$%#%#O
2
while True:#没啥好解释的这道 try: str1=input() counter = 0 for i in range(len(str1)): if str1[i].isupper() == True: counter =counter +1 print(counter) except: break
while True: try: import re print(len(re.findall('[A-Z]', input()))) except: break
import sys for line in sys.stdin: uplis = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" nn = [i for i in line if(i in uplis)] print(len(nn))
while True: try: str = input() count = 0 list = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V",'W',"X","Y","Z"] for i in str: if i in list: count += 1 print(count) except: break利用ASII码值判断:
while True: try: str = input() count = 0 for i in str: if 65 <= ord(i) <= 90: count += 1 print(count) except: break利用 isupper()函数判断:
while True: try: str = input() count = 0 for i in str: if i.isupper(): count += 1 print(count) except: break
import re print(len(re.findall("[A-Z]", input())))
python3