Question: Compare arrays (c++) a)Check if identical using a loop. Write a program which asks the user to enter two sequences of non-negative integers terminated by

Compare arrays (c++)

a)Check if identical using a loop. Write a program which asks the user to enter two sequences of non-negative integers terminated by 1. The program checks whether or not the two sequences are identical.

Sample Input/Output:

Enter the integers in the first sequence separated by spaces: 1 2 10 3 -1

Enter the integers in the second sequence separated by spaces: 1 2 10 3 -1

Sequences are equal

-------------

Enter the integers in the first sequence separated by spaces: 1 2 10 3 -1

Enter the integers in the second sequence separated by spaces: 2 1 10 3 -1

Sequences are not equal

-------------

Enter the integers in the first sequence separated by spaces: 1 2 10 3 -1

Enter the integers in the second sequence separated by spaces: 2 20 -1

Sequences are not equal

b)Check if permuted. Write a program which asks the user to enter a two sequences of integers and checks whether or not the second sequence is a permutation (reordering) of the first.

Sample Input/Output:

Enter the integers in the first sequence spearated by spaces: 1 2 10 3 10 10 10 -1

Enter the integers in the second sequence spearated by spaces: 10 10 2 10 1 3 10 -1

YES: second sequence is a permutation of the first

-------------

Enter the integers in the first sequence spearated by spaces: 1 2 -1

Enter the integers in the second sequence spearated by spaces: 1 1 -1

NO: second sequence is not a permutation of the first

-------------

Enter the integers in the first sequence spearated by spaces: 1 2 3 -1

Enter the integers in the second sequence spearated by spaces: 2 3 -1

NO: Second sequence is not a permutation of the first

NOTE : output must be as shown above. VECTORS NOT ALLOWED

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 Databases Questions!