HCI '16 - Unexpected Factorial

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Authors:
Problem types

In mathematics, the factorial of an integer (denoted by an ! symbol) is as follows:

0!=11!=12!=2×1=23!=3×2×1=64!=4×3×2×1=245!=5×4×3×2×1=120

On Reddit, there is a subreddit /r/unexpectedfactorial, dedicated to trolling users who have accidentally included a factorial in their post or comment.

Here are some examples of unexpected factorials:

Original: By 2007, I was only 5!

Response: Wow, 120 years old is quite old.

Original: Calculators explode when dividing by 0!

Response: Hmm, dividing by 1 shouldn't make your calculator explode…

Input Specification

Your program is required to detect an unexpected factorial N! (0N20) in a single line of text input, and output the actual value of N! (luckily for you, you are not required to phrase it into a statement). If the input does not contain any unexpected factorial, output -1. The input may contain spaces, punctuation and numbers.

The input should only contain 1 unexpected factorial, but may contain multiple exclamation marks.

Output Specification

Your program should output a single integer, the full actual value of N!.

Constraints

Subtask 1 [0%]

Sample test cases.

Subtask 2 [30%]

0N10

Subtask 3 [70%]

0N20

Sample Input 1

Copy
Nice! I rate 5/7!

Sample Output 1

Copy
5040

Sample Input 2

Copy
How obvious - how necessary - was the mathematical ratio of its sides, the quadratic sequence 1:4:9! (from 2001: A Space Odyssey)

Sample Output 2

Copy
362880

Sample Input 3

Copy
This string does not contain any unexpected factorial!

Sample Output 3

Copy
-1

Comments


  • -3
    gavin_chen  commented on May 23, 2022, 12:59 a.m.

    why am i getting #16 in batch 3 wrong?


  • -3
    YoInferno  commented on Sept. 11, 2021, 7:31 p.m.

    Can an input include no exclamation marks?


    • -2
      Spitfire720  commented on Dec. 29, 2021, 6:13 p.m.

      If the input does not contain any unexpected factorial, output -1


  • -1
    Swarley  commented on Jan. 13, 2019, 12:15 a.m.

    /r/theydidthemath