코드 >>
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
 | 
 using namespace std; 
class Solution { 
public: 
    string decodeString(string s) { 
        stack<pair<string, int>> decodeStack; 
        string tmp_num = ""; 
        string tmp_alpha = ""; 
        string tmp_str = ""; 
        string ans; 
        int tmp_int = 0; 
        int sSize = (int)s.size(); 
        int tmp_number = 0; 
        for (int i = 0; i < sSize; i++) 
        { 
            if (isalpha(s[i])) {                              
                ans = ans + s[i]; 
            } 
            else if (isdigit(s[i]) != 0) 
            { 
                tmp_num = tmp_num + s[i]; 
            } 
            else if (s[i] == '[') 
            { 
                decodeStack.push({ ans, stoi(tmp_num) }); 
                tmp_num = ""; 
                ans = ""; 
            } 
            else if (s[i] == ']') 
            { 
                tmp_str = decodeStack.top().first; 
                tmp_int = decodeStack.top().second; 
                decodeStack.pop(); 
                string temp_string = ""; 
                for (int j = 0; j < tmp_int; j++) 
                { 
                    temp_string = temp_string + ans; 
                }  
                ans = tmp_str + temp_string; 
            } 
        } 
        return ans; 
    } 
}; 
 | 
'C' 카테고리의 다른 글
| c++ leetcode 739 daily temperature code (0) | 2021.07.13 | 
|---|---|
| c++ leet code 227, Basic CalculatorII code (0) | 2021.07.12 | 
| c++ leetcode 155 Min Stack solution (double stack) (0) | 2021.07.08 | 
| c++ leetcode 1249 Minimum Remove to make valid parenthesis 문제풀이 (0) | 2021.07.08 | 
| c++ leet code 20. Valid Parentheses stack solution (0) | 2021.07.07 |