Huawei OD computer test-counting the number of capital letters (C++ & Java & JS & Python)

describe

Find the number of uppercase characters (i.e. 'A'-'Z') in the given string.

Data range: String length: 1≤∣�∣≤250 1≤∣s∣≤250 

The string may contain spaces or other characters

Advanced: Time complexity: �(�) O(n), Space complexity: �(�) O(n) 

Enter description:

For each set of samples, enter a line representing the string to be counted.

Output description:

Output an integer representing the number of uppercase letters in the string

Example 1

enter:

A 1 0 1 1150175017(&^%&$vabovbaoadd 123#$%#%#O

Output:

2

Java:

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) { 
            System.out.println(in.nextLine().replaceAll("[^A-Z]","").length());
        }
    }
}

python:

while True:
    try:
        n = input()
        c = ''
        for i in n:

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132873693