• + 0 comments

    I noticed that noone (including the test cases themselves) do any kind of validation. Not even against the constraints clearly noted in the problem itself?

    Is there a reason for this?

    I've tried submitting the below code, but it fails a few of the test cases. Unfortunately, I can't check why as the custom test input does not accept the input from the test cases due to size constraint. This tells me that for some of the test cases, the constraints are not met, and the test cases should have failed?

    import re
    
    try:
        num_of_words = int(input())
    except ValueError:
        raise Exception("Input was not a number")
    
    if num_of_words < 1 or num_of_words > 10**5:
        raise Exception("Too many words")
    
    try:
        word = input().strip()
    except EOFError:
        raise Exception("No input")
    
    word_dict = {}
    word_len_acc = 0
    while word:
        if re.match(r".*([A-Z]).*", word) or re.match(r".*([0-9]).*", word):
            raise Exception("No capital letters are allowed")
    
        if word not in word_dict.keys():
            word_dict[word] = 1
        else:
            word_dict[word] = word_dict[word] + 1
    
        word_len_acc += len(word)
        if word_len_acc > 10**6:
            raise Exception("Sum of word lengths can not exceed 1,000,000")
    
        try:
            word = input().strip()
        except EOFError:
            break
    
    
    print(len(word_dict.keys()))
    for num in sorted(word_dict.values(), reverse=True):
        print(num, end=" ")