Home / Expert Answers / Mechanical Engineering / write-a-program-that-takes-two-strings-str1-and-str2-from-the-user-and-prints-the-characters-that-pa268

(Solved): Write a program that takes two strings str1 and str2 from the user and prints the characters that ...



Write a program that takes two strings str1 and str2 from the user and prints the characters that appear in str1 and do not a

Write a program that takes two strings str1 and str2 from the user and prints the characters that appear in str1 and do not appear in str2 in a single line. It also prints all common characters between str1 and st2 and the character location in str1 and str2 one per line. Each input string is taken from a separate line. IMPORTANT NOTES Please follow the following guidelines when you print the output: - str1 is the first entered string and str 2 is the second entered string. - The order of the characters in the output must be in the same order of their appearance in str1 and str2. - Characters in str1 and not in str2 should be printed on one line separated be a single space. If no character satisfies this rule, then the code must output none (all small letters). - Each one of the common characters should be printed on a separate line. - When a common character appears at multiple indices in str 2 , the lowest index is printed. For example, in sample test case 1 , the common character ' \( r \) ' appears at index 1 and index 4 of string Program and the output shows only the lowest index (i.e. 1). - When a common character appears at multiple indices in str1, a separate line must be printed for each appearance. For example, in sample test case 1 , the common character ' \( \mathrm{g} \) ' appears at index 2 and index 10 of string Engineering and the output shows ' \( \mathrm{g} \) ' twice according to its order in the string. - The application is not case-sensitive which means that the capital letter and the small letter of the character are treated the same.(i.e. ' \( C \) ' \( = \) ' \( C \) ). \( 1 / 0 \) Program Input: Two lines each containing any string. Program Output: The first line shows characters in str 1 and not in str2, all on the same line separated by white space. \( N \) separate lines where each line has a letter that is common between str1 but not in str2 and its location (order starting from location 0 ) in str1 and str \( 2 . \)


We have an Answer from Expert

View Expert Answer

Expert Answer


The C++ program is as follows: #include #include using namespace std; int main() { string str1, str2; // to store the strings str1 and str2 cin>>str1; // Read str1 cin>>str2; // Read str2 int len2 = str2.length(); // L
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe