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
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 no digits follow.
Formulas can be concatenated together to produce another formula. For example, HOHeMg represents a combination of hydrogen oxygen helium and magnesium
Parentheses can be used to group elements, and a count optionally added applies to the entire group. For example, HO and HO 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 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 bit integer.
Input format:
input string formula representing a chemical formula
Output format:
Returns a string, which has occurance of all the elements followed by their count.
Constraints:
formula.length
formula consists of English letters, digits, and
formula is always valid.
Need Help? Contact us Please add
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
