Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  i
Language: C/C++
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int countt;
//for(countt=0;countt<5;countt++){
int allcard[104]={1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13};
int selectcard[4];
int count;
int randd;
for(count=0;count<4;count++){
srand((int)time(0));
randd=rand()%104;
if(allcard[randd]!=0){
selectcard[count]=allcard[randd];
allcard[randd]=0;
}
else
{count--;}
}
int result;
result=countcard(selectcard);
printf("%d",result);
//}
return 1;
}
int countcard(int selectcard[]){

int s=selectcard[0]+selectcard[1]+selectcard[2]+selectcard[3];
int maxx;


if(s>13){

  int tongji=0;
  maxx=selectcard[0];
  if(selectcard[1]>maxx) {selectcard[1]=selectcard[0];tongji=1;}
  if(selectcard[2]>maxx) {selectcard[2]=selectcard[0];tongji=2;}
  if(selectcard[3]>maxx) {selectcard[3]=selectcard[0];tongji=3;}
  selectcard[tongji]=0;
  s=s-maxx;
     if(s>13){
       int tongji=0;
       maxx=selectcard[0];
       if(selectcard[1]>maxx) {selectcard[1]=selectcard[0];tongji=1;}
       if(selectcard[2]>maxx) {selectcard[2]=selectcard[0];tongji=2;}
       if(selectcard[3]>maxx) {selectcard[3]=selectcard[0];tongji=3;}
       selectcard[tongji]=0;
       s=s-maxx;
         if(s>13){
            int tongji=0;
            maxx=selectcard[0];
            if(selectcard[1]>maxx) {selectcard[1]=selectcard[0];tongji=1;}
            if(selectcard[2]>maxx) {selectcard[2]=selectcard[0];tongji=2;}
            if(selectcard[3]>maxx) {selectcard[3]=selectcard[0];tongji=3;}
            selectcard[tongji]=0;
            s=s-maxx;
              if(s>13){
                 return 0;
                       }
               else {return 1;}
                 }
         else{return 2;}
               }
   else {return 3;}
}
else{return 4;}
}
Comments: