This is a memo for myself.
▼ Question
--The score (positive integer) for each match order is stored in the list. --Using the first score as a reference value, calculate the number of times the highest score was updated and the number of times the lowest score was updated.
▼sample input
python
scores =[3,4,21,36,10,28,35,5,24,42]
▼sample output
python
4 0
▼my answer
python
def breakingRecords(scores):
    high=low=scores[0]
    xhigh=xlow=0
    
    for i in scores:
        if i>high:
            xhigh+=1
            high=i
        elif i<low:
            xlow+=1
            low=i
    ans = [xhigh, xlow]
    return ans
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    n = int(input())
    scores = list(map(int, input().rstrip().split()))
    result = breakingRecords(scores)
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    fptr.close()
Recommended Posts