#P1898. Fate Calculation
Fate Calculation
Fate Calculation
Given two names and a positive integer \(\mathrm{ST}\), compute the "fate" number of the couple by following these steps:
- Extract the abbreviations: For each name, extract all uppercase letters (which represent the initials). For example, if the names are
JiangYunFan
andTangYuRou
, the abbreviations areJYF
andTYR
respectively, and concatenating them producesJYFTYR
. - Replace letters with numbers: Replace every letter with a number string according to the rule:
For each letter \(X\), replace it with \(\mathrm{ST}+k\) where \(k\) is such that \(X\) is the \((k+1))\text{-th}\) letter of the English alphabet. In particular:
\(A \to \mathrm{ST}\), \(B \to \mathrm{ST}+1\), \(C \to \mathrm{ST}+2\), \(...\), \(Z \to \mathrm{ST}+25\).
For example, if \(\mathrm{ST} = 81\), then \(J\) (the 10th letter) is replaced by \(81+9=90\), \(Y\) is replaced by \(81+24=105\), etc. Concatenating these replacements forJYFTYR
produces the number string901058610010598
. - Iterative digit reduction: Perform the following operation repeatedly on the number string:
- For the current string, sum every two adjacent digits and write down the ones digit (i.e. the last digit of the sum) to form a new string.
- This operation reduces the length of the string by one. Continue the process until the string either becomes exactly100
or its length is less than or equal to 2 (note that a string starting with a leading zero counts as two digits).
The final number (after converting the resulting string to an integer, ignoring any leading zeros) is the "fate" number.
Example:
- Names:
JiangYunFan
andTangYuRou
- Abbreviation:
JYFTYR
- With \(\mathrm{ST}=81\), the letter-to-number mapping gives: \(J\to90\), \(Y\to105\), \(F\to86\), \(T\to100\), \(Y\to105\), \(R\to98\); concatenated into
901058610010598
. - After several iterations of adjacent digit summing, the final string becomes
01
, which is interpreted as the integer1
(the couple's fate number).
Your task is to implement a program that, given two names and an integer \(\mathrm{ST}\), computes and prints the fate number.
inputFormat
Input Format:
- The first line contains a string representing the first person's name.
- The second line contains a string representing the second person's name.
- The third line contains a positive integer \(\mathrm{ST}\).
Note: Each name is provided in CamelCase such that each word starts with an uppercase letter. It is guaranteed that each name contains at least one uppercase letter.
outputFormat
Output Format:
Print a single integer: the calculated fate number.
sample
JiangYunFan
TangYuRou
81
1
</p>