six seven
This commit is contained in:
@@ -141,5 +141,49 @@ Output:
|
||||
15 18
|
||||
\end{verbatim}
|
||||
|
||||
% ========================= Problem 4 =========================
|
||||
\problem{Problem 3: Merge Intervals}
|
||||
\textit{Difficulty: Hard}
|
||||
|
||||
You are given a string S composed of only the characters ‘6’, ‘7’, ‘A’, ‘B’, and ‘#’ (without the quotation marks). This string is processed from left to right, and you must maintain a sequence of chracters that changes according to these rules:
|
||||
1. The sequence starts out empty.
|
||||
2. 6 - add a 6 to the end of the sequences
|
||||
3. 7 - if the sequence is non-empty and its last chracter is ‘6’, remove that last ‘6’, otherwise, add ‘7’ to the end of the sequence
|
||||
4. A - reverse the sequence
|
||||
5. B - add a duplicate of the current sequence to the end of it
|
||||
6. # - clear the sequence
|
||||
|
||||
\inputformat
|
||||
\begin{itemize}
|
||||
\item The first line consists of the string S. The string consists only of the characters 6, 7, A, B, and #.
|
||||
\item $|S|$ ($1 \leq n \leq 10^5$), the number of intervals.
|
||||
\end{itemize}
|
||||
|
||||
\outputformat
|
||||
\begin{itemize}
|
||||
\item Output a single line containig the final form of the sequence. If the sequence is empty at the end, output “EMPTY” (without the quotations).
|
||||
\end{itemize}
|
||||
|
||||
\examples
|
||||
\begin{verbatim}
|
||||
Input 1:
|
||||
67A6
|
||||
|
||||
Output 1:
|
||||
6
|
||||
|
||||
Input 2:
|
||||
66B7
|
||||
|
||||
Output 2:
|
||||
666
|
||||
|
||||
Input 3:
|
||||
7A7#
|
||||
|
||||
Output 3:
|
||||
EMPTY
|
||||
\end{verbatim}
|
||||
|
||||
\end{document}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user