Question: WRITE A C PROGRAM: TEMPLATE: #include #include void readPerm(int perm[], int len); int checkPerm(const int perm[], int len); int main() { int length; int readOK;

WRITE A C PROGRAM:

WRITE A C PROGRAM: TEMPLATE: #include #include void readPerm(int perm[], int len);

int checkPerm(const int perm[], int len); int main() { int length; int

TEMPLATE:

#include

#include

void readPerm(int perm[], int len);

int checkPerm(const int perm[], int len);

int main()

{

int length;

int readOK;

readOK = scanf("%d", &length);

while (readOK && (length > 0)) {

int perm[length+1];

readPerm(perm, length);

int isSuper = checkPerm(perm, length);

printf("%ssuper ", (isSuper ? "" : "not "));

readOK = scanf("%d", &length);

}

return 0;

}

/*

Read len integers, and save them to perm[1], perm[2], and so on.

perm has (len + 1) elements. 0, 1, ..., len.

perm[0] is not used. It is safe to write to perm[len].

*/

void readPerm(int perm[], int len)

{

// Write a loop to read len integers.

// In each iteration, use scanf to read an integer into

// a temporary variable, and then copy it to the right

// element in the array.

// Remember to start with perm[1].

// TODO

}

// return 1 for superpermutations, 0 otherwise.

// remember

// 1. perm has (len + 1) elements. perm[0] is not used.

// 2. check if the value is between 1 and len.

int checkPerm(const int perm[], int len)

{

// TODO

int isSuper = 1;

return isSuper;

}

A permutation of the integers from 1 to n is an ordering of these integers. A natural way to represent a permutation is to list the integers in the desired order. For example, for n = 5, a permutation might look like 2, 3, 4, 5, 1. However, there is alternative way of representing a permutation: you create a list of n numbers where the i-th number is the position of integer i in the permutation. For the above permutation this alternative representation is 5, 1, 2, 3, 4 since 1 appears on position 5, 2 appears on position 1, and so on (note that in math position numbering starts from 1). A super-permutation is a permutation for which the two representations are identical. For example, 1, 4, 3, 2 is a super-permutation. You have to write a program which detects if a given permutation is a super-permutation or not. A template is provided. Do not modify main) in the template. Input: The program should read from the standard input one or more test cases. In each case, the program first reads an integer n (1

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!