Translate

Views

Thursday, April 11, 2024

Solution UVA: 324 - Factorial Frequencies

 

 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss324 - Factorial Frequencies AcceptedPython0.0200.00036621 mins ago

Suggest:
- BigNumber (so we should code python to easy)

def f(n):
    if n == 0:
        return 1
    else:
        return n * f(n - 1)

while True:
    n = int(input())
   
    if n == 0:
        break
   
    cnt = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
    for c in str(f(n)):
        cnt[c] += 1
   
    print(f"{n}! --")
   
    print(f"   ({0}){cnt[str(0)]:>5}", end="")
    for i in range(1, 5):
        print(f"    ({i}){cnt[str(i)]:>5}", end="")
   
    print()
   
    print(f"   ({5}){cnt[str(5)]:>5}", end="")
    for i in range(6, 10):
        print(f"    ({i}){cnt[str(i)]:>5}", end="")
   
    print()


No comments: