题解 | #HJ84 统计大写字母个数#
统计大写字母个数
http://www.nowcoder.com/practice/434414efe5ea48e5b06ebf2b35434a9c
C语言版本
#include <stdio.h>
int main() {
char s[251];
scanf("%[^\n]", s);
int count = 0;
for (int i = 0; i < strlen(s); i++) {
if ('A' <= s[i] && s[i] <= 'Z') {
count += 1;
}
}
printf("%d\n", count);
return 0;
}
Python版本
while True:
try:
content = input()
count = len([i for i in content if i.isupper()])
print(count)
except:
break