1 条题解

  • 0
    @ 2025-9-17 8:48:01

    python当中没有scanf这种东西,所以我用find()找'['位置,再切片

    from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
    
    a = {
        "B":0,
        "KB":1,
        "MB":2,
        "GB":3,
        "TB":4,
        "PB":5,
        "EB":6,
        "ZB":7,
        "YB":8
    }
    
    n, = re()
    for i in range(1, n + 1):
        s = input()
        idx = s.find('[')
        s = s[idx + 1 : -1]
        print(f"Case #{i}: {100 - 100 * pow(1000 / 1024, a[s]):.2f}%")
    
    
    

    由于python强处理字符串和其解包特性,也可以这样写:

    from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
    
    a = {
        "B":0,
        "KB":1,
        "MB":2,
        "GB":3,
        "TB":4,
        "PB":5,
        "EB":6,
        "ZB":7,
        "YB":8
    }
    
    n, = re()
    for i in range(1, n + 1):
        *_, s = input().strip(']').split('[')
        print(f"Case #{i}: {100 - 100 * pow(1000 / 1024, a[s]):.2f}%")
    
    
    • 1

    信息

    ID
    388
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    (无)
    递交数
    5
    已通过
    2
    上传者