OK here is my code
#include<stdio.h>
#include<algorithm>
#include<utility>
using namespace std;
int compareints (const void * a, const void * b)
{
  return ( *(long*)a - *(long*)b );
}


int main()
    {
    int n,s[101],a,b,c,d,e,f;
    long p1[100009],p2[100009];
    int i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&s[i]);
    //sort(s,s+i);
     k=0;
    for(i=0;i<n;i++)
        {
        for(j=0;j<n;j++)
        {
        for(int l=0;l<n;l++)
            {
            if(s[l])
        p1[k++]=(s[i]+s[j])*s[l];
        }
        }
        }
        //sort(p1,p1+k);
        int x=0;
        for(i=0;i<n;i++)
        {
        for(j=0;j<n;j++)
        {
        for(int l=0;l<n;l++)
            {
            //if(s[l]!=0)
        p2[x++]=(s[i]*s[j])+s[l];
        }
        }
        }
        sort(p2,p2+x);
        long *pItem;
        long count=0;
        for(i=0;i<k;i++)
            {
            pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
compareints);
            if(pItem){

            long *tmp=pItem;
                        if(pItem==p2)while(*(tmp)==p1[i]&&tmp<p2+x){
count++;tmp++;}
            else
                            if(pItem==(p2+(x-1))) {
while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
                else{
                                tmp++;
                                while(*(tmp)==p1[i]&&tmp<p2+x){
count++;tmp++;}

while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
                }
             //count++;
            }
            }
            printf("%ld\n",count);

        //for(i=0;i<k;i++) printf("%ld ",p1[i]);printf("\n");
        //for(i=0;i<x;i++) printf("%ld ",p2[i]);printf("\n");
    return 0;
    }


Why is it getting segmentation fault?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to