Цитата
#include <stdio.h>
#include <memory.h>
#include <malloc.h>
#define MAXBUF 16
int getcoord(int x, int y, int m_sz){
return (m_sz*y)+x;
}
int f_match(char* dots,int dot,int r){
int i=0;
for (;i<r;i++){
if (dots[i]==dot) return 1;
}
return 0;
}
void f_next(const int c_dot,const int sz_m,const char* adj_matr,char* vis,int aux){
int i=0;
int crd;
vis[aux]=c_dot+48;
vis[sz_m]=0;
if (aux>0) printf("%s\n",vis);
while (i<sz_m){
crd=getcoord(i,c_dot,sz_m);
if ((adj_matr[crd]=='1')&&(f_match(vis,i+48,sz_m)==0)) {
f_next(i,sz_m,adj_matr,vis,aux+1);
}
i+=1;
}
vis[aux]=0;
}
int main(int arc, char **argv){
char *matr;
char *vis;
int sz_m=0;
char buff[MAXBUF];
FILE* fh;
int i=0;
fh = fopen("input.txt","r");
fgets(buff,MAXBUF,fh);
sz_m=atoi(buff);
matr=(char*)malloc(sizeof(char)*sz_m*sz_m);
vis = (char*)malloc(sizeof(char)*sz_m);
bzero(matr,sz_m*sz_m);
for (;i<sz_m;i++){
fgets(buff,MAXBUF,fh);
memcpy(&matr[sz_m*i],buff,sz_m);
bzero(buff,MAXBUF);
}
fclose(fh);
for(i=0;i<sz_m;i++){
bzero(vis,sz_m);
f_next(i,sz_m,matr,vis,0);
}
}
#include <memory.h>
#include <malloc.h>
#define MAXBUF 16
int getcoord(int x, int y, int m_sz){
return (m_sz*y)+x;
}
int f_match(char* dots,int dot,int r){
int i=0;
for (;i<r;i++){
if (dots[i]==dot) return 1;
}
return 0;
}
void f_next(const int c_dot,const int sz_m,const char* adj_matr,char* vis,int aux){
int i=0;
int crd;
vis[aux]=c_dot+48;
vis[sz_m]=0;
if (aux>0) printf("%s\n",vis);
while (i<sz_m){
crd=getcoord(i,c_dot,sz_m);
if ((adj_matr[crd]=='1')&&(f_match(vis,i+48,sz_m)==0)) {
f_next(i,sz_m,adj_matr,vis,aux+1);
}
i+=1;
}
vis[aux]=0;
}
int main(int arc, char **argv){
char *matr;
char *vis;
int sz_m=0;
char buff[MAXBUF];
FILE* fh;
int i=0;
fh = fopen("input.txt","r");
fgets(buff,MAXBUF,fh);
sz_m=atoi(buff);
matr=(char*)malloc(sizeof(char)*sz_m*sz_m);
vis = (char*)malloc(sizeof(char)*sz_m);
bzero(matr,sz_m*sz_m);
for (;i<sz_m;i++){
fgets(buff,MAXBUF,fh);
memcpy(&matr[sz_m*i],buff,sz_m);
bzero(buff,MAXBUF);
}
fclose(fh);
for(i=0;i<sz_m;i++){
bzero(vis,sz_m);
f_next(i,sz_m,matr,vis,0);
}
}