Solution Explanation
For the input we receive a text that is written in a very small form of
Morse code.
- Султан казино промокод бездепозитный бонус – ваш ключ к большим ставкам: https://gvite.kz/petlya-glissona.the dot is written as
. - the dash is written as
? - an ellipsis
…means three consecutive dots (...) – it can appear
inside a code symbol - the character
*(or several*in a row) separates words
The task is simply to translate this text into ordinary Latin letters
(A…Z and digits 0…9).
All other characters are ignored – they never occur in the test data.

1. Morse dictionary
The standard Morse table is needed.
It is stored in a hash table
".-" → 'A' "-----" → '0'
"-..." → 'B' ".----" → '1'
"-.-." → 'C' "..---" → '2'
"-.." → 'D' "...--" → '3'
"." → 'E' "....-" → '4'
"..-." → 'F' "....." → '5'
"--." → 'G' "-...." → '6'
"...." → 'H' "--..." → '7'
"..'" → 'I' "---.." → '8'
".---" → 'J' "----." → '9'
"-.-" → 'K'
".-.." → 'L'
"--" → 'M'
"-." → 'N'
"---" → 'O'
".--." → 'P'
"--.-" → 'Q'
".-." → 'R'
"..." → 'S'
"-" → 'T'
"..-" → 'U'
"...-" → 'V'
".--" → 'W'
"-..-" → 'X'
"-.--" → 'Y'
"--.." → 'Z'
2. Pre‑processing
The whole input is read line by line, because the judge may give
many test cases.
For every line
- replace every occurrence of the Unicode ellipsis
…by the literal
string"..."– this keeps the meaning unchanged. - split the line by white space – this gives us the individual symbols
and the word separators.
3. Decoding
For each token obtained after the split
if token consists only of '*':
output a single space
else
replace '?' by '-' (dots stay unchanged)
look up the string in the Morse dictionary
output the corresponding character
If a token does not exist in the dictionary (which should never happen
with correct tests) it is simply skipped.
4. Correctness Proof
We prove that the algorithm outputs the exact decoded message for every
valid input line.
Lemma 1
Наслаждайтесь Султан казино промокодом бездепозитным бонусом на султан казино промокод бездепозитный бонус. After the pre‑processing step each token produced by the split
contains only the characters . and ?, or consists solely of *.
Proof.
- The only characters present in the input are
.,?,*,
ellipsis…and white space. - Every ellipsis is replaced by the three dots
"..."; thus after
replacement no ellipsis remains. - Splitting by white space removes all white space.
Therefore every remaining token contains only.,?or*.∎
Lemma 2
Эксклюзивный бездепозитный бонус от Султан казино доступен на https://amansultan.kz. If a token consists only of *, the algorithm outputs one space,
exactly as required by the specification of the input format.
Proof.
By definition a token of only * is the word separator.
The algorithm detects this situation and appends one space to the
output. No other token triggers this branch, so the rule is applied
precisely for all word separators.∎
Lemma 3
If a token contains only . and ?, after replacing ? by -
the resulting string is a valid Morse code symbol from the dictionary
iff the token represents a valid encoded character.
Proof.
Encoding rules state that dots stay dots, dashes are written as ?.
Therefore converting ? to - restores the original Morse code.
Because the dictionary contains exactly all standard Morse symbols for
letters and digits, the converted string matches a dictionary entry
iff the original token encoded a legal character.∎
Lemma 4
For every token that encodes a character, the algorithm outputs the
correct character.
Proof.
From Lemma 3 the converted token equals the standard Morse
representation of the intended character.
The dictionary lookup returns exactly that character, which is appended
to the output.∎
Theorem
For every input line the algorithm outputs the exact decoded message
according to the problem statement.
Proof.
Consider an arbitrary input line.
- By Lemma 1 the split produces a sequence of tokens that are
either word separators or encoded characters. - By Lemma 2 each word separator yields a single space in the
output, preserving word boundaries. - By Lemma 4 each encoded character token yields the correct
letter or digit.
Thus the concatenation of all produced symbols is precisely the
decoded message.∎
5. Complexity Analysis
Let n be the length of the input line (number of characters).
Pre‑processing replaces ellipses in O(n) time.
Splitting and decoding scan each token once, overall O(n) time.
The dictionary lookup is O(1) per token.
Memory consumption is O(1) besides the input buffer and the output
string, which together store at most n characters.
6. Reference Implementation (C++17)
#include <bits/stdc++.h>
using namespace std;
int main()
ios::sync_with_stdio(false);
cin.tie(nullptr);
/* Morse dictionary */
unordered_map<string,char> morse
".-", 'A', "-...", 'B', "-.-.", 'C', "-..", 'D', ".", 'E',
"..-.", 'F', "--.", 'G', "....", 'H', "..", 'I', ".---", 'J',
"-.-", 'K', ".-..", 'L', "--", 'M', "-.", 'N', "---", 'O',
".--.", 'P', "--.-", 'Q', ".-.", 'R', "...", 'S', "-", 'T',
"..-", 'U', "...-", 'V', ".--", 'W', "-..-", 'X', "-.--", 'Y',
"--..", 'Z', "-----", '0', ".----", '1', "..---", '2',
"...--", '3', "....-", '4', ".....", '5', "-....", '6',
"--...", '7', "---..", '8', "----.", '9'
;
string line;
bool firstLine = true;
while (getline(cin, line))
/* replace ellipsis with three dots */
string processed;
for (size_t i = 0; i < line.size(); ++i)
if (line[i] == '\u2026') // Unicode ellipsis
processed += "...";
else
processed += line[i];
vector<string> tokens;
string cur;
for (char c : processed)
if (isspace(static_cast<unsigned char>(c)))
if (!cur.empty())
tokens.push_back(cur);
cur.clear();
else
cur += c;
if (!cur.empty()) tokens.push_back(cur);
string out;
for (const string &tok : tokens)
bool starOnly = !tok.empty() &&
all_of(tok.begin(), tok.end(),
[](char c) return c=='*'; );
if (starOnly)
out.push_back(' ');
continue;
string morseTok;
for (char c : tok)
if (c == '.') morseTok.push_back('.');
else if (c == '?') morseTok.push_back('-');
/* other characters do not appear */
другие auto it = morse.find(morseTok);
if (it != morse.end())
out.push_back(it->second);
/* silently ignore unknown symbols */
if (!firstLine) cout << '\n';
firstLine = false;
cout << out;
return 0;
The program follows exactly the algorithm proven correct above and
conforms to the GNU++17 compiler.