PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 10107 (What is the Median?)
in 0.420 seconds using as much as 428 kbytes of virtual memory.

void main()
{
    int a[10000],i,j,k,n=0;
    char s[1000];

    while (gets(s)!=NULL) {
        i=0; while (s[i]==' ') i++;
        sscanf(s+i,"%d",&k);
        for (i=0;i<n;i++) if (a[i]>=k) break;
        for (j=n-1;j>=i;j--) a[j+1]=a[j];
        a[i]=k; n++;
        if (n%2==1) printf("%d\n",a[n/2]);
        else printf("%d\n",(a[n/2]+a[n/2-1])/2);
    }
}    
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:1.878毫秒