Using stack explained
Approach\n\nInitialization: \nWe use a stack to handle nested structures and a map to store counts of each atom. We also use a vector to handle multipliers due 
# Approach\n\nInitialization: \nWe use a stack to handle nested structures and a map to store counts of each atom. We also use a vector to handle multipliers due to parentheses.\n\nParsing the Input:\nTraverse the string and identify if the character is:\nAn uppercase letter (start of an atom).\nA lowercase letter (continuation of an atom name).\nA digit (multiplier for the previous atom or group).\nA parenthesis (indicating a nested structure).\n\nHandling Atoms and Numbers:\nWhen an uppercase letter is encountered, we extract the full atom name by checking subsequent lowercase letters.\nIf digits follow, they represent the count of the preceding atom. If not, the default count is 1.\nWhen digits are encountered directly, they indicate the multiplier for the preceding structure inside parentheses.\n\nUsing the Stack:\nPush atoms and their counts onto the stack.\nUse a multiplier stack to handle nested parentheses and their multipliers.\nWhen encountering a closing parenthesis, we calculate the total multiplier for the nested structure.\nConstructing the Final Count:\nPop elements from the stack, applying the multipliers to calculate the total counts.\nUse a map to accumulate counts for each atom.\n\nGenerating the Output:\nconstruct the final output string with atom counts.\n\n# Code\n```\nclass Solution {\npublic:\n    string countOfAtoms(string fr) {\n        stack<string>st;\n        for(int i = 0 ; i < fr.size() ;){\n             if(fr[i]>64 && fr[i]<91){\n                int j = i+1;\n                while(j<fr.size() && fr[j]>96 && fr[j]<123) j++;\n                st.push(fr.substr(i,j-i));\n                i=j;\n                if(j<fr.size() && fr[j]>47 && fr[j]<58) continue;\n                else st.push("1");\n             }\n             else if(fr[i]>47 && fr[i]<58){\n                int j = i+1;\n                while(j<fr.size() && fr[j]>47 && fr[j]<58) j++;\n                st.push(fr.substr(i,j-i));  \n                i=j;              \n             }\n             else{\n                string t = "";\n                t += fr[i];\n                st.push(t);\n                i++;\n                if(t ==")" && (i>=fr.size() || fr[i]<48 || fr[i]>57)) st.push("1"); \n             }\n        }\n        map<string,int> mp;\n        vector<int>mult;\n        mult.push_back(1);\n        while(!st.empty()){\n            string s = st.top();\n            st.pop();\n            // cout<<s<<"  ";\n            // continue;\n            if(s[0]>47 && s[0]<58){\n               mult.push_back((stoi(s))*(mult[mult.size()-1]));\n            }\n            else if(s[0]>64 && s[0]<91){\n                mp[s] += mult[mult.size()-1];\n                mult.pop_back();\n            }\n            else if(s == "("){\n                mult.pop_back();\n            }\n\n        }\n        string ans = "";\n        for(auto x : mp ){\n            ans += (x.first);\n            if(x.second != 1){\n                ans+= to_string(x.second);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']