Process the text line by line. Since the lines may contain spaces and any other characters, each line is read as a whole using the getline function. Reading continues until the end of the input, since the number of lines is not known in advance.
In each line, iterate over the characters one by one. If the current character is an uppercase Latin letter, that is, '' ≤ ≤ '', then its cost equals s[i] - 'A' + 1: the letter '' costs , '' costs , ..., '' costs . All other characters (lowercase letters, digits, punctuation marks, spaces) are skipped.
The required product is accumulated in the variable . Initially, set res = 1. This value is also the answer if the text contains no uppercase Latin letters.
The product of the costs quickly becomes huge, so take the remainder modulo 10^9 + 7 after each multiplication.
Example
The given example contains the following uppercase Latin letters:
The cost of each letter is given in parentheses. The product of all the costs is
Algorithm implementation
Define the modulus used to compute the product.
#define MOD 1000000007The required product is computed in the variable . Initially, it is set to .
res = 1;Read the text line by line until the end of the input.
while (getline(cin, s))
{Iterate over the characters of the current line .
for (i = 0; i < s.size(); i++)
{If the current character is an uppercase Latin letter, compute its cost and multiply by modulo .
if (('A' <= s[i]) && (s[i] <= 'Z'))
{
c = s[i] - 'A' + 1;
res = (res * c) % MOD;
}
}
}Print the answer.
cout << res << endl;