Company: Trilogy Innovations Sde intern Oncampus_17july
Difficulty: hard
A cryptarithm is a letter-and-digit puzzle: you must find a way to swap each distinct letter for a digit so that the arithmetic sentence spelled out in letters becomes a true equation. You are given a cryptarithm as three words word1 , word2 , word3 , standing for the equation word1 + word2 = word3 Count how many valid solutions this puzzle has. A solution counts as valid when every distinct letter maps to a different digit (0–9), and no multi-digit number's leading digit is zero. Note. A single-letter word represents a one-digit number, so that letter is allowed to map to 0. Input Format The program reads from standard input: Line 1: the string word1 Line 2: the string word2 Line 3: the string word3 Each word is non-empty and contains only uppercase English letters. Output Format Print a single integer to standard output: the number of valid solutions, followed by a newline. Print 0 if there are none. Constraints 1 ≤ length of each word ≤ 35 Every character is an uppercase