PersonalCorpus 版 (精华区)
Your C++ program has solved Ok the problem 441 (Lotto)
in 0.010 seconds with low memory spent.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
int i,k,s[100];
int res[6];
void tryit (int pos, int dep)
{
int i;
if (dep==6) {
printf("%d %d %d %d %d %d\n",res[0],res[1],res[2],res[3],
res[4],res[5]);
return;
}
for (i=pos;i<k;i++) {
res[dep]=s[i];
tryit(i+1,dep+1);
}
}
int cmp(const void *a, const void *b)
{
if (*(int *)a>*(int *)b) return 1;
if (*(int *)a==*(int *)b) return 0; else return -1;
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input441.txt","r",stdin);
freopen("c:\\uva\\output441.txt","w",stdout);
#endif
scanf("%d",&k);
while (1) {
for (i=0;i<k-1;i++) scanf("%d",&s[i]);
scanf("%d\n",&s[k-1]);
qsort((void *)s,k,4,cmp);
tryit(0,0);
scanf("%d",&k); if (k>0) printf("\n"); else break;
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.239毫秒