📄 makestakes.cpp
字号:
//makestakes.cpp
#include "stdafx.h"
#include "win.h"
#include "winDlg.h"
#include "makestakes.h"
#include<fstream.h>
#include<iostream.h>
#include<math.h>
int num[14];
char ary[14][3];
char site[14];
int icount = 0;
char **alloc2(int r,int c)
{
char *x,**y;
int n;
x=(char *)calloc(r*c,sizeof(char));
y=(char **)calloc(r,sizeof(char *));
for(n=0;n<=r-1;n++)
y[n]=&x[c*n];
return y;
}
int mulnum(char c)
{
switch(c)
{
case 0 :
case 1 :
case 3 : return 1;
case 4 :
case 5 :
case 6 : return 2;
case 7 : return 3;
case 8 : return 1;//
default : exit(1);
}
}
void expand(char ch, char whole[3])
{
switch(ch)
{
case 0 : whole[0] = '0'; return ;
case 1 : whole[0] = '1'; return ;
case 3 : whole[0] = '3'; return ;
case 4 : whole[0] = '0'; whole[1] = '1'; return ;
case 5 : whole[0] = '0'; whole[1] = '3'; return ;
case 6 : whole[0] = '1'; whole[1] = '3'; return ;
case 7 : whole[0] = '0'; whole[1] = '1'; whole[2] = '3'; return ;
case 8 : whole[0] = '*'; return;// 任九
default : exit(1);
}
}
int calnum(char multiple[14])
{
int n = 1;
for(int i = 0; i < 14; i++)
{
num[i] = mulnum(multiple[i]);
n = n * num[i];
}
return n;
}
void backtrack(int n, char **single) //回溯算法计算所有展开式
{
int i;
if(n == 14)
{
for(i = 0; i < 14; i++)
single[icount][i] = site[i];
icount++;
return ;
}
for( i = 0; i < num[n]; i++)
{
site[n] = ary[n][i];
backtrack(n+1, single); //递归
}
}
int makestakes(char multiple[14], int& n,char **single)
{
int i, j;
char whole[3];
n = calnum(multiple);
for(i = 0; i < 14; i++)
{
expand(multiple[i],whole);
for(j = 0; j < 3; j++)
{
if(j < num[i]) ary[i][j] = whole[j];
else ary[i][j] = 0;
}
}
backtrack(0, single);
// cout<<icount<<endl;
return 0;
}
void seticount(void)
{
icount=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -