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

BESTBATS - Top Batsmen, WA, help pls.

$
0
0

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;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



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