示例#1
0
文件: shuodu.c 项目: olliezhu/shuodu
void
calculate_sudoku(void)
{
    get_sudoku();
}
示例#2
0
/****************MAIN************/ 
int main(int argc, char **argv){ 
  clock_t start,end; 
  int row;
  char line[100],filename[100];
  int s_time;
  srand(time(NULL));
  start=clock();
  
  /* get the puzzle*/
  if(argc<2){
    printf("Input a file name.\n");
    fgets(line,sizeof(line),stdin);
    sscanf(line,"%s",filename);
  }
  else
    strcpy(filename,argv[1]);
    
  fp=fopen(filename,"r");
  if(!fp){
    printf("File not found.\n");
    exit(1);
  }
  get_sudoku(fp); 
  fclose(fp); 
  printf("The given solution:\n"); 
  print_table(sudoku,stdout); // print the sudoku puzzle
  
  /* Check if there is any conflict in the input puzzle.*/
  if(check_conflict())
    return 0;
  
  if(argc>2){
    limit_empty=atoi(argv[2]);
  }
  else{
    printf("Please Enter number of empty grids you want.\n(MAXIMUM=%d)\n",LIMIT_EMPTY);
    fgets(line,sizeof(line),stdin);
    limit_empty=atoi(line);
  }
  
  while(limit_empty>LIMIT_EMPTY){
    printf("Too large number.Input again!\n");
    fgets(line,sizeof(line),stdin);
    limit_empty=atoi(line);
  }
 
  if(limit_empty>=55){
    norm=limit_empty-50;
  }
  else
    norm=4;
  max_empty=limit_empty-norm;

  if(limit_empty>=55){
    if(limit_empty==58){
      printf("Please wait. Depend on the puzzle, this process may take up to several ten minutes.\n");
      printf("Press Crl+C to terminate the process\n");
    }
    else
      printf("Please wait a minute or less.\n");
  }
  
  create();
  if(max_empty>=limit_empty){
    printf("SUCCESS.\n");
    printf("\nThe sudoku puzzle.\nNumber of empty grids=%d\n",max_empty);
    print_table(result,stdout);
    printf("Result is saved in result.txt.\n");
  }
  else
    printf("FAILURE.\n");
  
  if(max_empty==LIMIT_EMPTY){
    system("cat result.txt best.txt>new_best.txt");
    system("mv new_best.txt best.txt");
  }
  
  end=clock();
  printf("Time elapsed: %e(s)\n",(double)(end-start)/CLOCKS_PER_SEC);
  return 0; 
}