BESTBATS - Top Batsmen, WA, help pls.

http://www.codechef.com/problems/BESTBATS getting wa. here is my code: http://ideone.com/E8AnqD

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int cmp(const void *a, const void *b) {
	return(*(int*)b - *(int*)a);
}

unsigned int fact(unsigned int a) {
	return (a==1 || a==0) ? 1 : fact(a-1)*a;
}

int main() {
	int t, p[11], k, tot, act, pas, el, r;
	scanf("%d", &t);
	while(t--) {
		act=0; pas=0; tot=0; el=0;
		for(int i=0; i<11; i++) scanf("%d", &p[i]);
		scanf("%d", &k);
		qsort(p, 11, sizeof(int), cmp);
		el=p[10-k];
		for(int i=10; i>k-1; i--) if(el==p[i]) act++;
		for(int i=k-1; i>0; i--) if(el==p[i]) pas++;
		tot=act+pas; r=0; r=fact(tot)/(fact(act)*fact(tot-act));
		printf("%d\n", r);
	}
	return 0;
}

OMG :slight_smile: i cant believe, got AC. hurray: http://ideone.com/QpJR8X

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int fact(int a) {
	return (a==1 || a==0) ? 1 : fact(a-1)*a;	
}

int cmp(const void *a, const void *b) {
	return (*(int*)b - *(int*)a);
}

int main() {
	int t, p[12], k, k_th, in, out, tot;;
	scanf("%d", &t);
	while(t--) {
		for(int i=0; i<11; i++) scanf("%d", &p[i]); scanf("%d", &k);
		qsort(p, 11, sizeof(int), cmp); 
		k_th=p[k-1]; in=out=tot=0;
		for(int i=0; i<k; i++) if(k_th==p[i]) in++;
		for(int i=k; i<11; i++) if(k_th==p[i]) out++;
		tot=in+out;
		printf("%d\n", fact(tot)/(fact(in)*fact(tot-in)));
	}
	return 0;
}

how can i accept right answer?

You did it in a bad way… You can vote up an answer (possibly more) with “thumb up” icon and accept the answer with “tick” icon. You can do both (but not sure if you can do that with your own questions and answers)…