C++ || Beats 46% || Map, String, Vector,Stack
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string countOfAtoms(string formula) {\n        map<string, long long> um;\n        stack<int> st;\n        stack<char> s;\n        string a;\n        unordered_set<char> se = {\'0\', \'1\', \'2\', \'3\', \'4\',\n                                  \'5\', \'6\', \'7\', \'8\', \'9\'};\n        for (int i = 0; i < formula.size(); i++) {\n            if (!s.empty()) {\n                if (se.find(s.top()) == se.end() && s.top() != \'(\' &&\n                    s.top() != \')\' &&\n                    ((formula[i] >= \'A\' && formula[i] <= \'Z\') ||\n                     (formula[i] == \'(\' || formula[i] == \')\'))) {\n                    s.push(\'1\');\n                }\n            }\n            s.push(formula[i]);\n        }\n        if (se.find(s.top()) == se.end()){\n            s.push(\'1\');\n        }\n        while (!s.empty()) {\n            a += s.top();\n            s.pop();\n        }\n        reverse(a.begin(), a.end());\n        cout<<a<<endl;\n        vector<vector<string>> v, v1;\n        int i = 0;\n        while (i < a.size()) {\n            int j = i;\n\n            string s1, s2;\n            if (a[j] == \'(\') {\n                v.push_back({"(", "0"});\n                j++;\n            } // else if (a[i] == \')\') {\n            //     int k = j;\n            //     while (v[k][0] != \'(\') {\n            //         int b = v[k][1] - \'0\';\n            //     }\n            // }\n            else {\n                if(a[j]==\')\'){\n                    s1=")";\n                    j++;\n                }else{\n                while (a[j] != \'\\0\' && se.find(a[j]) == se.end()) {\n                    s1 += a[j];\n                    j++;\n                }}\n                while (a[j] != \'\\0\' && se.find(a[j]) != se.end()) {\n                    s2 += a[j];\n                    j++;\n                }\n                if(s2==""){\n                    s2="1";\n                }\n                if (s1 == ")") {\n                    long long k = v.size() - 1, c;\n                    stringstream ss;\n                    ss << s2;\n                    ss >> c;\n                    cout<<c<<"aaaa"<<endl;\n                    while (v[k][0] != "(") {\n                        long long b = c * stoi(v[k][1]);\n                        v[k][1] = to_string(b);\n                        k--;\n                    }\n                    v.erase(v.begin() + k);\n                } else {\n                    v.push_back({s1, s2});\n                }\n            }\n            i = j;\n        }\n\n        // sort(v.begin(),v.end());\n        for(auto &i:v){\n            cout<<i[0]<<"\\t"<<i[1]<<endl;\n        }\n        for (int i = 0; i < v.size(); i++) {\n            // um[i[0]]=atoi(i[1]);\n            if (um.find(v[i][0]) == um.end()) {\n                stringstream ss;\n                long long aa, bb;\n                ss << v[i][1];\n                ss >> aa;\n                cout << aa << endl;\n                um[v[i][0]] = aa;\n            }\n            // else if(v[i][0]==v[i+1][0]){\n            //     stringstream ss;\n            //     long long aa,bb;\n            //     ss<<v[i][1];\n            //     ss<<v[i+1][1];\n            //     // long aa=stoi(v[i][1]),bb=stoi(v[i+1][1]);\n            //     ss>>aa;\n            //     ss>>bb;\n            //     cout<<aa<<"jyg"<<bb<<endl;\n            //     aa=aa+bb;\n            //     v[i][1]=to_string(aa);\n            //     v1.push_back(v[i]);\n            //     v.erase(v.begin()+i+1);\n            // }\n            // else if(i==v.size()-2){\n            //     v1.push_back(v[i]);\n            //     v1.push_back(v[i+1]);\n            // }\n            else {\n                stringstream ss;\n                long long aa, bb;\n                ss << v[i][1];\n                ss >> aa;\n                // um[v[i][0]]=aa;\n                map<string, long long>::iterator itr = um.find(v[i][0]);\n                itr->second += aa;\n            }\n        }\n        a = "";\n        for (map<string, long long>::iterator itr = um.begin(); itr != um.end();\n             itr++) {\n            a += itr->first;\n            if (itr->second != 1) {\n                a += to_string(itr->second);\n            }\n        }\n        cout << a;\n        return a;\n    }\n};\n```
['Hash Table', 'String', 'Stack', 'Sorting', 'C++']