2010-04-16 - DATA STRUCTURE BODLOGO BIE DAALTANDAA ASHIGLAARAI
#include
#include
#include
/*#include
/*#include
int i1,i,j,j1,i2,j2,n,m,f;
int a[21][21];
FILE*p;
int nuudel(int x,int y, int k)
{
if(x+1<=n&&(a[x+1][y]==0)){ a[x+1][y]=k+1;
nuudel(x+1,y,k+1);
a[x+1][y]=0;
}
if(x-1>0&&(a[x-1][y]==0)){ a[x-1][y]=k+1;
nuudel(x-1,y,k+1);
a[x-1][y]=0;
}
if(y+1<=m&&(a[x][y+1]==0)){ a[x][y+1]=k+1;
nuudel(x,y+1,k+1);
a[x][y+1]=0;
}
if(y-1>0&&(a[x][y-1]==0)){ a[x][y-1]=k+1;
nuudel(x,y-1,k+1);
a[x][y-1]=0;
}
if(x-1>0&&y-1>0&&(a[x-1][y-1]==0)){ a[x-1][y-1]=k+1;
nuudel(x-1,y-1,k+1);
a[x-1][y-1]=0;
}
if(x-1>0&&y+1<=m&&(a[x-1][y+1]==0)){a[x-1][y+1]=k+1;
nuudel(x-1,y+1,k+1);
a[x-1][y+1]=0;
}
if(x+1<=n&&y+1<=m&&(a[x+1][y+1]==0)){a[x+1][y+1]=k+1;
nuudel(x+1,y+1,k+1);
a[x+1][y+1]=0;
}
if(x+1<=n&&y-1>0&&(a[x+1][y-1]==0)){a[x+1][y-1]=k+1;
nuudel(x+1,y-1,k+1);
a[x+1][y-1]=0;
}
if((x==1||x==n)||(y==1||y==m)){
int r,t; f++; fprintf(p,"
%d-r bolomj
%d,%d-s %d-r muriin %d-r bagana hureh zam
",f,i1,j1,x,y);
for(r=1;r<=n; r++){ for(t=1;t<=m; t++){fprintf(p,"%3d",a[r][t]); }
fprintf(p,"
");}
}
}
main(void)
{
clrscr();
FILE*s;
p=fopen("urdun.txt","a");
s=fopen("f3.cpp","r");
if(s==NULL) printf("
BOLOHGUI BNA
");
printf(" BOLJ BNA
");
fscanf(s,"%d",&n);
fscanf(s,"%d",&m);
fscanf(s,"%d",&i1);
fscanf(s,"%d",&j1);
for(i=1; i<=n; i++) for(j=1; j<=m; j++) fscanf(s,"%d",&a[i][j]);
a[i1][j1]=-1;
fclose(s);
/*for(i=1;i<=n;i++)
{for(j=1;j<=m;j++)
{if(((i==1||i==n)&&(j==1||j==m))&&a[i][j]==0){i2=i;j2=j;*/nuudel(i1,j1,1);// ;}}}
printf("duuslaaa urdun.txt file-g har");
printf("
niit %d bolomj bna.",f);
getch();
fclose(s);
}
//TOORDOG BAISHINTAI BODLOGO
//ZAM NI
10 10
2 2
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 1 1 1 0 1 0 1
1 0 1 0 1 0 1 1 0 1
1 0 0 0 0 1 0 1 0 1
1 0 1 0 1 0 1 1 0 1
1 0 1 0 1 0 0 1 0 1
1 0 1 0 1 0 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 0 1
//MAZE
#include
#include
#include
#include
#include
unsigned int e[2][500],r[2][500],u=1000,d,f,t=0; /* ZAMIIG hadgalah */
unsigned long E[2][1000],R[2][1000],U=0,D,F,T=0; /* hol zam */
unsigned long h=0; /* TOOLUUR */
int z,x,c,v; /*2 tseg */
int size=20,nuh=15,bk=0,fill=14,l=8,g=10,text=14,del=100,rad=nuh/3; /*graph color */
unsigned long a[61][61];
int zur(int X,int Y)
{ if(rad==0||rad==1){
setfillstyle(1,g);
floodfill((2*Y-1)*nuh/2,(2*X-1)*nuh/2,l);
}
else {
setcolor(g);
setfillstyle(1,g);
circle((2*Y-1)*nuh/2,(2*X-1)*nuh/2,rad);
floodfill((2*Y-1)*nuh/2,(2*X-1)*nuh/2,g);
}
return 0;
}
int aril(int C,int V )
{ if(rad==0||rad==1){
setfillstyle(1,bk);
floodfill((2*V-1)*nuh/2,(2*C-1)*nuh/2,l);
}
else {
setcolor(bk);
setfillstyle(1,bk);
circle((2*V-1)*nuh/2,(2*C-1)*nuh/2,rad);
floodfill((2*V-1)*nuh/2,(2*C-1)*nuh/2,bk);
}
return 0;
}
int zam(int I,int J,int o)
{
if(I==c&&J==v)
if(t for(d=0; d<2; d++)
for(f=0; f<=t; f++)
r[d][f]=e[d][f];
u=t; }
if(I!=c||J!=v){
e[0][o]=I;
e[1][o]=J;
t=o; }
return 0;
}
int hol_zam(int I1,int J1,int O)
{
if(I1==c&&J1==v)
if(T>U){
for(D=0; D<2; D++)
for(F=0; F<=T; F++)
R[D][F]=E[D][F];
U=T; }
if(I1!=c||J1!=v){
E[0][O]=I1;
E[1][O]=J1;
T=O; }
return 0;
}
int start(int i1,int j1,int i2, int j2)
{
setfillstyle(1,4);
floodfill((2*j1-1)*nuh/2,(2*i1-1)*nuh/2,l);
if(nuh>7){
setcolor(1);
outtextxy((2*j1-1)*nuh/2-3,(2*i1-1)*nuh/2-3,"S"); }
setfillstyle(1,4);
floodfill((2*j2-1)*nuh/2,(2*i2-1)*nuh/2,l);
if(nuh>7){
setcolor(1);
outtextxy((2*j2-1)*nuh/2-3,(2*i2-1)*nuh/2-3,"E");}
return 0;
}
int nuudel(int x,int y, int k)
{
if(x+1<=size&&(a[x+1][y]==0||a[x+1][y]>k+1)){ a[x+1][y]=k+1;
zur(x+1,y);
delay(del);
zam(x+1,y,k+1);
hol_zam(x+1,y,k+1);
nuudel(x+1,y,k+1);
aril(x+1,y);
a[x+1][y]=0;
delay(del);
}
if(x-1>0&&(a[x-1][y]==0||a[x-1][y]>k+1)){ a[x-1][y]=k+1;
zur(x-1,y);
delay(del);
zam(x-1,y,k+1);
hol_zam(x-1,y,k+1);
nuudel(x-1,y,k+1);
a[x-1][y]=0;
aril(x-1,y);
delay(del);
}
if(y+1<=size&&(a[x][y+1]==0||a[x][y+1]>k+1)){ a[x][y+1]=k+1;
zur(x,y+1);
delay(del);
zam(x,y+1,k+1);
hol_zam(x,y+1,k+1);
nuudel(x,y+1,k+1);
a[x][y+1]=0;
aril(x,y+1);
delay(del);
}
if(y-1>0&&(a[x][y-1]==0||a[x][y-1]>k+1)){ a[x][y-1]=k+1;
zur(x,y-1);
delay(del);
zam(x,y-1,k+1);
hol_zam(x,y-1,k+1);
nuudel(x,y-1,k+1);
a[x][y-1]=0;
aril(x,y-1);
delay(del);
}
}
main()
{
int x1,y1;
unsigned int i,j;
FILE*s;
s=fopen("zam1.txt","r");
if(s==NULL) printf("
BOLOHGUI BNA
");
printf(" BOLJ BNA
");
for(i=1; i<=size; i++)
for(j=1; j<=size; j++) fscanf(s,"%d",&a[i][j]);
fclose(s);
for(i=1; i<=size; i++)
for(j=1; j<=size; j++){ if(a[i][j]==5){ a[i][j]=-1; z=i; x=j; }
if(a[i][j]==6){ c=i; v=j; a[i][j]=0;}
}
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"d:\tc\bgi");
setbkcolor(bk);
setcolor(l);
for(i=0; i<=size; i++){x1=i*nuh; y1=i*nuh;
line(0,y1,nuh*size,y1);
line(x1,0,x1,nuh*size-1);
}
for(i=0; i
{ setfillstyle(1,fill);
floodfill((2*j+1)*nuh/2,(2*i+1)*nuh/2,l);
}
start(z,x,c,v);
setcolor(text);
outtextxy(size*nuh+7,5," (1)-g darbal EHELNE");
if(getch()!='1') exit(1);
setcolor(bk);
outtextxy(size*nuh+7,5," (1)-g darbal EHELNE");
setcolor(text);
outtextxy(size*nuh+7,15," PLEASE WAIT...");
nuudel(z,x,0);
setcolor(bk);
outtextxy(size*nuh+7,15," PLEASE WAIT...");
setcolor(text);
outtextxy(size*nuh+7,20,"Hamgiin Hol zam (h)");
outtextxy(size*nuh+7,50,"Hamgiin Oir zam (o)");
int Q;
Q=getch();
setcolor(bk);
outtextxy(size*nuh+7,20,"Hamgiin Hol zam (h)");
outtextxy(size*nuh+7,50,"Hamgiin Oir zam (o)");
switch(Q)
{ case 'o':
for(i=0; i<=u; i++){ zur(r[0][i],r[1][i]);
sound(2000);
delay(del*2);
nosound();
}
setcolor(text);
outtextxy(size*nuh+7,25,"Hamgiin Oir zam");
outtextxy(size*nuh+7,50,"NUUSEN NUUDEL ");
gotoxy(size*nuh/8+9,5);
printf("%u",u+1);
break;
case'h':
for(i=0; i<=U; i++){ zur(R[0][i],R[1][i]);
sound(2000);
delay(del*2);
nosound();
}
setcolor(text);
outtextxy(size*nuh+7,25,"Hamgiin Hol zam");
outtextxy(size*nuh+7,50,"NUUSEN NUUDEL ");
gotoxy(size*nuh/8+8,5);
printf("%u",U+1);
break;
exit(1);
}
start(z,x,c,v);
getch();
fclose(s);
}
//ZAM NI
6 8
2 3
1 0 0 1 0 0 1 0
0 1 0 0 1 1 0 0
1 1 0 1 0 0 1 0
0 0 1 1 0 1 0 1
0 1 0 0 1 0 0 1
0 0 1 1 0 1 0 0
//MINESWEEPER
#include
#include
#include
#include
#include
#include
int a[50][50]={0},isize=20,jsize=20,mintoo=100;
int too(int x,int y)
{ int t=0;
if(x-1>0&&y-1>0&&a[x-1][y-1]==-1){t=t+a[x-1][y-1];}
if(x-1>0&&a[x-1][y]==-1){t=t+a[x-1][y]; }
if(x-1>0&&y+1<=jsize&&a[x-1][y+1]==-1){t=t+a[x-1][y+1];}
if(y-1>0&&a[x][y-1]==-1){t=t+a[x][y-1];}
if(y+1<=jsize&&a[x][y+1]==-1){t=t+a[x][y+1];}
if(x+1<=isize&&y-1>0&&a[x+1][y-1]==-1){t=t+a[x+1][y-1];}
if(x+1<=isize&&a[x+1][y]==-1){t=t+a[x+1][y];}
if(x+1<=isize&&y+1<=jsize&&a[x+1][y+1]==-1){t=t+a[x+1][y+1];}
return abs(t);
}
int zadar(int x,int y)
{if(too(x,y)==0){
if(x-1>0&&y-1>0&&a[x-1][y-1]==0){a[x-1][y-1]=9;zadar(x-1,y-1);}
if(x-1>0&&a[x-1][y]==0){a[x-1][y]=9;zadar(x-1,y); }
if(x-1>0&&y+1
if(y+1<=jsize&&a[x][y+1]==0){a[x][y+1]=9;zadar(x,y+1);}
if(x+1
if(x+1
else{a[x][y]=too(x,y);}
};
random()
{int x,y;
while(mintoo>0){
x=rand()%isize+1;
y=rand()%jsize+1;
if(a[x][y]==0){a[x][y]=-1;mintoo--;}
}
}
void main()
{int i,j,x,y;
clrscr();
random();
int hojigd=1;
while(hojigd){
gotoxy(1,1);
clrscr();
for(i=1; i<=isize; i++){printf("
");
for(j=1; j<=jsize;j++){if(a[i][j]==-1){printf("%2d",0); }
else printf("%2d",a[i][j]);
}
}
printf("
");
printf("
too x y ");
scanf("%d %d",&x,&y);
if(a[x][y]==-1)
{ clrscr();for(i=1; i<=isize; i++){printf("
");
for(j=1; j<=jsize;j++) printf("%2d",a[i][j]); }
hojigd=0;
}
else { if(x<=isize&&y<=jsize)zadar(x,y);
else{gotoxy(30,25); printf("Aldaaa");getch();}
}
}
getch();
}