LoginSignup
0
0

More than 3 years have passed since last update.

【python】最高・最低記録の更新回数を求めるプログラム

Posted at

自分用のメモです。

▼設問

  • listに試合順ごとの得点(正の整数)が格納されている。
  • 初回の得点を基準値として、最高得点を更新した回数と、最低得点を更新した回数をそれぞれ求める。

URL

▼sample input

scores =[3,4,21,36,10,28,35,5,24,42]

▼sample output

4 0

▼my answer

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()



・tabulate
表にする。
She tabulates the number of times she breaks her season record.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0