well explained story c++
Intuition\n Describe your first thoughts on how to solve this problem. \njust divide it into 3 parts open bracket,closed bracket and rest.\n# Approach\n Describ
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\njust divide it into 3 parts open bracket,closed bracket and rest.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n#if (\'rest\') you need to find element and number\n    *there can be possibility that element can be like Mg,Na so consider that and make  string of that and moving forward find the number for that patricular element  and store it in map of type string and int.\n\n#if \'(\' just store your current  map in stack, clear the map and move forward   \n\n#if \')\' here you need to find the multiplier so move forward and find the multiplier.Now at this time you must have something in your stack  and map just add all those in map carefully.\n\nnow just traverse the map and add it in your resultant string and return it\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string countOfAtoms(string s) {\n        int n=s.size();\n        stack<map<string,int>>st;\n        map<string,int>curr;\n        int i=0;\n        while(i<n){\n            \n            if(s[i]==\'(\'){\n                st.push(curr);\n                curr.clear();\n                i++;\n            }else if(s[i]==\')\'){\n                i++;\n                int start=i;\n                while(i<n && isdigit(s[i]))i++;\n                int multi = (i > start) ? stoi(s.substr(start, i - start)) : 1;\n                map<string,int>temp=st.top();\n                st.pop();\n                for(auto&[key,val]:curr){\n                    temp[key]+=val*multi;\n                }\n                curr=temp;\n            }else{\n                \n                int start=i;\n                i++;\n                while(i<n && islower(s[i]))i++;\n                string atom = s.substr(start, i - start);\n                start=i;\n                while(i<n && isdigit(s[i]))i++;\n                int cnt = (i > start) ? stoi(s.substr(start, i - start)) : 1;\n                curr[atom]+=cnt;\n            }\n            \n        }\n        string result;\n        for (auto&[atom, count] : curr) {\n            result += atom;\n            if (count > 1) result += to_string(count);\n        }\n        return result;\n    }\n};\n```
['C++']