Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Finding number of average elements

$
0
0

The question is to find the number of average elements in an array .(http://opc.iarcs.org.in/index.php/problems/AVERAGE) I know that this can be made efficient but I wanted to try to code the NxNxN solution as well. However, it's giving a wrong answer. What am I missing?

#include <iostream>
#include <algorithm>
using namespace std;

int main() {

        int n,a[10001];
        int count = 0;
        cin>>n;
        for(int i=0;i<n;i++)
        cin>>a[i];
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<n;j++)
                {

                        for(int k=j+1;k<n;k++)
                        {
                               if(((a[k]+a[j])==2*a[i]))
                                {
                                    count++;
                                }

                        }
                }

        }
        cout<<count<<endl;
        return 0;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>