|
|
|
|
@ -0,0 +1,61 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
|
int number;
|
|
|
|
|
char name[100];
|
|
|
|
|
char information[10000];
|
|
|
|
|
}VertexType;//<2F><><EFBFBD><EFBFBD>ṹ
|
|
|
|
|
typedef struct{
|
|
|
|
|
VertexType ver[20];//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
int arcs[100][100];//<2F>ڽӾ<DABD><D3BE><EFBFBD>
|
|
|
|
|
int vexnum, edgenum;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵĸ<DFB5><C4B8><EFBFBD>;
|
|
|
|
|
}Graph;//ͼ<>ṹ
|
|
|
|
|
|
|
|
|
|
int getVerNum(Graph &g, char* name){//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ,<2C><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>-1
|
|
|
|
|
for(int i=0;i<g.vexnum;i++){
|
|
|
|
|
if(strcmp(g.ver[i].name,name)==0){
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
int main(){
|
|
|
|
|
Graph g;
|
|
|
|
|
FILE *fp,*fl;
|
|
|
|
|
if((fp=fopen("D:\\111code_project\\Graphs\\Graph.txt","r"))==NULL){//<2F><><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
cout<<"Cannot open this file!"<<endl;
|
|
|
|
|
}
|
|
|
|
|
if((fl=fopen("C:\\Users\\86133\\Desktop\\laji.txt","w"))==NULL){//<2F><><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
cout<<"Cannot open this file!"<<endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(fp,"%d %d",&g.vexnum, &g.edgenum);
|
|
|
|
|
fprintf(fl,"%d %d\n",g.vexnum, g.edgenum);
|
|
|
|
|
for(int i=0;i<g.vexnum;i++){
|
|
|
|
|
g.ver[i].number=i;
|
|
|
|
|
fscanf(fp,"%s %s",g.ver[i].name, g.ver[i].information);
|
|
|
|
|
fprintf(fl,"%-20s %s\n",g.ver[i].name, g.ver[i].information);
|
|
|
|
|
}
|
|
|
|
|
for(int k=0;k<g.edgenum;k++){//while(!feof(fp)) for(int k=0;k<g.edgenum;k++)
|
|
|
|
|
int n;
|
|
|
|
|
char d1[20],d2[20];
|
|
|
|
|
fscanf(fp,"%s %s %d",d1,d2,&n);
|
|
|
|
|
fprintf(fl,"%-20s %-20s %-2d\n",d1,d2,n);
|
|
|
|
|
int i=getVerNum(g,d1); int j=getVerNum(g,d2);
|
|
|
|
|
g.arcs[i][j]=n; g.arcs[j][i]=n;
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<g.vexnum;i++){
|
|
|
|
|
for(int j=0;j<g.vexnum;j++){
|
|
|
|
|
printf("%-2d ",g.arcs[i][j]);
|
|
|
|
|
}
|
|
|
|
|
cout<<"\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
fclose(fl);//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|