diff options
1 files changed, 29 insertions, 0 deletions
| -rw-r--r-- | Sem. 06/Solutions/exercise05.cpp | 29 |
diff --git a/Sem. 06/Solutions/exercise05.cpp b/Sem. 06/Solutions/exercise05.cpp new file mode 100644 index 0000000..17eb52b --- /dev/null +++ b/Sem. 06/Solutions/exercise05.cpp @@ -0,0 +1,29 @@ +#include <iostream> + +using namespace std; + +int inversionsCount(int nums[], int len) { + int count = 0; + + for (int i = 0; i <= len - 2; i++) { + for (int j = i + 1; j <= len - 1; j++) { + if (nums[i] > nums[j]) + count++; + } + } + + return count; +} + +int main() { + const int MAX_N = 1000; + + int n; + cin >> n; + + int nums[MAX_N] = { 0 }; + for (int i = 0; i < n; i++) + cin >> nums[i]; + + cout << inversionsCount(nums, n) << endl; +} |
