@Akshata I managed to get AC with majority algorithm.
suggestions: 1) You can try to read input and find candidate in same loop 2) Use scanf and printf Thanks, Balaji. On Tue, Feb 15, 2011 at 4:30 PM, jai gupta <[email protected]> wrote: > #include<stdio.h> > #include<string.h> > #include<malloc.h> > void work() { > int n,max,maxpos,x,i; > scanf("%d",&n); > int *arr=(int*) malloc(sizeof(int)*2005); > memset(arr,0,2005); > max=maxpos=0; > > for(i=0;i<n;i++) > { > scanf("%d",&x); > arr[x+1000]++; > if(arr[x+1000]>max) > { > max=arr[x+1000]; > maxpos=x; > } > } > if(max>n/2) > printf("YES %d\n",maxpos,max); > else > printf("NO\n"); > } > int main() { > int t; > > scanf("%d",&t); > while(t--) > work(); > > return 0; > } > > -- > 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. > -- 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.
