3612. Process String with Special Operations I Medium

@problem@discussion
#String#Simulation



1/**
2 * [3612] Process String with Special Operations I
3 *
4 * You are given a string s consisting of lowercase English letters and the special characters: *, #, and %.
5 * Build a new string result by processing s according to the following rules from left to right:
6 * 
7 * 	If the letter is a lowercase English letter append it to result.
8 * 	A '*' removes the last character from result, if it exists.
9 * 	A '#' duplicates the current result and appends it to itself.
10 * 	A '%' reverses the current result.
11 * 
12 * Return the final string result after processing all characters in s.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">s = "a#b%*"</span>
17 * Output: <span class="example-io">"ba"</span>
18 * Explanation:
19 * <table style="border: 1px solid black;">
20 * 	<thead>
21 * 		<tr>
22 * 			<th style="border: 1px solid black;">i</th>
23 * 			<th style="border: 1px solid black;">s[i]</th>
24 * 			<th style="border: 1px solid black;">Operation</th>
25 * 			<th style="border: 1px solid black;">Current result</th>
26 * 		</tr>
27 * 	</thead>
28 * 	<tbody>
29 * 		<tr>
30 * 			<td style="border: 1px solid black;">0</td>
31 * 			<td style="border: 1px solid black;">'a'</td>
32 * 			<td style="border: 1px solid black;">Append 'a'</td>
33 * 			<td style="border: 1px solid black;">"a"</td>
34 * 		</tr>
35 * 		<tr>
36 * 			<td style="border: 1px solid black;">1</td>
37 * 			<td style="border: 1px solid black;">'#'</td>
38 * 			<td style="border: 1px solid black;">Duplicate result</td>
39 * 			<td style="border: 1px solid black;">"aa"</td>
40 * 		</tr>
41 * 		<tr>
42 * 			<td style="border: 1px solid black;">2</td>
43 * 			<td style="border: 1px solid black;">'b'</td>
44 * 			<td style="border: 1px solid black;">Append 'b'</td>
45 * 			<td style="border: 1px solid black;">"aab"</td>
46 * 		</tr>
47 * 		<tr>
48 * 			<td style="border: 1px solid black;">3</td>
49 * 			<td style="border: 1px solid black;">'%'</td>
50 * 			<td style="border: 1px solid black;">Reverse result</td>
51 * 			<td style="border: 1px solid black;">"baa"</td>
52 * 		</tr>
53 * 		<tr>
54 * 			<td style="border: 1px solid black;">4</td>
55 * 			<td style="border: 1px solid black;">'*'</td>
56 * 			<td style="border: 1px solid black;">Remove the last character</td>
57 * 			<td style="border: 1px solid black;">"ba"</td>
58 * 		</tr>
59 * 	</tbody>
60 * </table>
61 * Thus, the final result is "ba".
62 * </div>
63 * <strong class="example">Example 2:
64 * <div class="example-block">
65 * Input: <span class="example-io">s = "z*#"</span>
66 * Output: <span class="example-io">""</span>
67 * Explanation:
68 * <table style="border: 1px solid black;">
69 * 	<thead>
70 * 		<tr>
71 * 			<th style="border: 1px solid black;">i</th>
72 * 			<th style="border: 1px solid black;">s[i]</th>
73 * 			<th style="border: 1px solid black;">Operation</th>
74 * 			<th style="border: 1px solid black;">Current result</th>
75 * 		</tr>
76 * 	</thead>
77 * 	<tbody>
78 * 		<tr>
79 * 			<td style="border: 1px solid black;">0</td>
80 * 			<td style="border: 1px solid black;">'z'</td>
81 * 			<td style="border: 1px solid black;">Append 'z'</td>
82 * 			<td style="border: 1px solid black;">"z"</td>
83 * 		</tr>
84 * 		<tr>
85 * 			<td style="border: 1px solid black;">1</td>
86 * 			<td style="border: 1px solid black;">'*'</td>
87 * 			<td style="border: 1px solid black;">Remove the last character</td>
88 * 			<td style="border: 1px solid black;">""</td>
89 * 		</tr>
90 * 		<tr>
91 * 			<td style="border: 1px solid black;">2</td>
92 * 			<td style="border: 1px solid black;">'#'</td>
93 * 			<td style="border: 1px solid black;">Duplicate the string</td>
94 * 			<td style="border: 1px solid black;">""</td>
95 * 		</tr>
96 * 	</tbody>
97 * </table>
98 * Thus, the final result is "".
99 * </div>
100 *  
101 * Constraints:
102 * 
103 * 	1 <= s.length <= 20
104 * 	s consists of only lowercase English letters and special characters *, #, and %.
105 * 
106 */
107pub struct Solution {}
108
109// problem: https://leetcode.com/problems/process-string-with-special-operations-i/
110// discuss: https://leetcode.com/problems/process-string-with-special-operations-i/discuss/?currentPage=1&orderBy=most_votes&query=
111
112// submission codes start here
113
114impl Solution {
115    pub fn process_str(s: String) -> String {
116        String::new()
117    }
118}
119
120// submission codes end
121
122#[cfg(test)]
123mod tests {
124    use super::*;
125
126    #[test]
127    fn test_3612() {
128    }
129}
130

Back
© 2026 bowen.ge All Rights Reserved.