Answered step by step
Verified Expert Solution
Question
1 Approved Answer
String s contains lowercase letters, digits, ( and ), satisfying the following rules: - Two digits cannot be adjacent. - Two ( cannot be
String s contains lowercase letters, digits, "(" and ")", satisfying the following rules: - Two digits cannot be adjacent. - Two "(" cannot be adjacent. - One "(" and one ")" cannot be adjacent. - After any digit, there must be "(". - The quantities of "(" and ")" are equal. Change string s until new string t created, t contains only lowercase letters. These are changing rules: - Sub-strings with form "n(p)", can change to "pp...p" (n times p), where n is a digit and p is a string. - If p still contains "(", ")" or digits, continue to implement the above changing method. Request: Implement function expand (string s); Where s is a string with the above form; return the result is a string containing only lowercase letters. Example: - String "2(ab3(cde)x)" changes into "abcdecdecdexabcdecdecdex". - String "2(x0 )3(z)" changes into "xxzzz". Note: In this exercise, libraries iostream, string and using namespace std; have been used. You can add other functions for your answer, but you are not allowed to add other libraries. For example: Result Test cout < < expand("2(ab3(cde)x)") < < " "; abcdecdecdexabcdecdecdex cout < < expand("2(x0(y))(z)") < < " "; xxzzz
Step by Step Solution
★★★★★
3.42 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
To implement the expand function you can use a stack to keep track of the characters and their count...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started