11674 - 231001_11/16_practice9-2
|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
Description
-
An inversion in an array a[] is an index pair (i,j) such that i<j but a[i]>a[j] .
-
Write a function int num_inv(int *a, int n) to take two input parameters: an integer array a[] and its size n.
-
Your function should return the number of inversions in a[].
-
Write a main function to get an input array and then pass it to num_inv().
-
You may assume that the array size is at least 1 and no more than 20 (so you should declare an array of size 20 in the main function).
-
All numbers are positive, and the input termination sentinel is -1 (-1 doesn't contain in the array you need to count).
Input
-
Input: A sequence
-
Input format: A sequence with the end of -1
Output
-
Output: The number of Inversions
-
Output:
-
An integer
-
Change a new line at the end
Tags