fork download
  1. #include <iostream>
  2. using namespace std;
  3. int getCount(int n,int arr[]){
  4. int count=0;
  5. for(int i=0;i<=n-3;i++){
  6. for(int j=i+1;j<=n-2;j++){
  7. for(int k=j+1;k<=n-1;k++){
  8. if(arr[i]>arr[j] && arr[j]<arr[k]){
  9. count++;
  10. }
  11. }
  12. }
  13. }
  14. return count;
  15. }
  16.  
  17. int main() {
  18. // your code goes here
  19. int n;
  20. cin>>n;
  21. int arr[n];
  22. for(int i=0;i<n;i++){
  23. cin>>arr[i];
  24. }
  25. cout<<"The count of valid triplets is:"<<getCount(n,arr);
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5288KB
stdin
6
8 1 2 3 4 5
stdout
The count of valid triplets is:10