1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include<iostream>
#include<string.h>
using namespace std;
int tyrsene3(char matrica[4][4],int n,int a,int b,int a1[4][4],char duma[10])
{
if(a<0||a>3||b<0||b>3)
{return 0;}
else
{
if(a1[a][b]==0)
{
if(n!=2)//Here I check if I am at the last character
{ duma[n]=matrica[a][b];
a1[a][b]=1;
n++;
tyrsene3(matrica,n,a-1,b-1,a1,duma);
tyrsene3(matrica,n,a-1,b,a1,duma);
tyrsene3(matrica,n,a-1,b+1,a1,duma);
tyrsene3(matrica,n,a,b-1,a1,duma);
tyrsene3(matrica,n,a,b+1,a1,duma);
tyrsene3(matrica,n,a+1,b-1,a1,duma);
tyrsene3(matrica,n,a+1,b,a1,duma);
tyrsene3(matrica,n,a+1,b+1,a1,duma);
a1[a][b]=0;
n--;
return 0;
}
else
{
duma[n]=matrica[a][b];
duma[n+1]='\0';
cout<<duma<<" ";
return 1;
}
}
else return 0;
}
}
void dumichka(char matrica[][4],int start, int end,int a1[4][4])
{ char duma[5];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
a1[i][j]=0;
tyrsene3(matrica,0,start,end,a1,duma);
}
int main()
{
char matrica[4][4];
int a1[4][4];
char bukva='a';
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{matrica[i][j]=bukva;
bukva++;}
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
dumichka(matrica,i,j,a1);
return 0;
}
|