Question: The program can be on c or c++ Suppose you have a string made up of only the letters 'A' and 'B'. Write a program
The program can be on c or c++
Suppose you have a string made up of only the letters 'A' and 'B'. Write a program that checks if the string was generated using the following rules: the string begins with an 'A' each 'A' is followed by nothing or an 'A' or "BB" each "BB" is followed by nothing or an 'A' For example, these are some valid strings: A AA AAABB ABBABB AAAABBAAAABBABBAABB But the following are not valid strings: BB ABBBBA BBABBA BABBABB ABBABBAAABBABBABBBB Your program should read in an unknown number of various sized strings from the data file and output, print either "VALID" or "INVALID", depending on the string's validity, followed by the siring. The data file is found at ~dmk0080/public/1040/labs/exam 1/string and contains one siring of 'A's and "B" on each line. For example, for the input below: BB AAABB ABBBBA AA BBABBA ABBABBAAABBABBABBBB AAAABBAAAABBABBAABB ABBABB A BABBABB the output should be: INVALID BB VALID AAABB INVALID ABBBBA VALID AA INVALID BBABBA INVALID ABBABBAAABBABBABBBB VALID AAAABBAAAABBABBAABB VALID ABBABB VALID A INVALID BABBABB Suppose you have a string made up of only the letters 'A' and 'B'. Write a program that checks if the string was generated using the following rules: the string begins with an 'A' each 'A' is followed by nothing or an 'A' or "BB" each "BB" is followed by nothing or an 'A' For example, these are some valid strings: A AA AAABB ABBABB AAAABBAAAABBABBAABB But the following are not valid strings: BB ABBBBA BBABBA BABBABB ABBABBAAABBABBABBBB Your program should read in an unknown number of various sized strings from the data file and output, print either "VALID" or "INVALID", depending on the string's validity, followed by the siring. The data file is found at ~dmk0080/public/1040/labs/exam 1/string and contains one siring of 'A's and "B" on each line. For example, for the input below: BB AAABB ABBBBA AA BBABBA ABBABBAAABBABBABBBB AAAABBAAAABBABBAABB ABBABB A BABBABB the output should be: INVALID BB VALID AAABB INVALID ABBBBA VALID AA INVALID BBABBA INVALID ABBABBAAABBABBABBBB VALID AAAABBAAAABBABBAABB VALID ABBABB VALID A INVALID BABBABB
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
