Question: write code in CPP of the following questions. Coding ( Question 2 Q Revisit Later How to Attempt? Fastenal, a leading logistics company, manages a

write code in CPP of the following questions.
Coding
(
Question 2
Q Revisit Later
How to Attempt?
Fastenal, a leading logistics company, manages a vast fleet of cargo containers that transport goods across the globe. Each container contains a mix of elements, and Fastenal wants to keep track of the count of each atom in their cargo.
The cargo containers are labeled with chemical formulas, which represent the composition of the cargo. The formulas follow these rules:
An atomic element always starts with an uppercase character, followed by zero or more lowercase letters representing the element's name.
One or more digits may follow the element's name, indicating its count. If the count is 1, no digits follow.
Formulas can be concatenated together to produce another formula. For example, "H2O2He3Mg4" represents a combination of hydrogen (H), oxygen (O), helium (He), and magnesium (Mg).
Parentheses can be used to group elements, and a count (optionally added) applies to the entire group. For example, "(H2O2)" and "(H2O2)3" are valid formulas.
Fastenal needs your help to compute the count of all elements in their cargo containers. The output should be a string in the following format: the first element name (sorted alphabetically), followed by its count (if greater than 1), then the second element name (sorted alphabetically), and so on.
Note: Fastenal's cargo containers are carefully labeled, and the test cases are designed to ensure that all values in the output fit within a 32-bit integer.
Input format:
input1- string formula representing a chemical formula
Output format:
Returns a string, which has occurance of all the elements followed by their count.
Constraints:
1 formula.length 1000
formula consists of English letters, digits, '(', and ')'
formula is always valid.
Need Help? Contact us (Please add
write code in CPP of the following questions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!