Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<conio.h>
- using namespace std;
- FILE *graph;
- int n,//количество вершин
- m;//количество ребер
- int **ms;
- int v,u,w;//начальная вершина,конечная, вес ребра
- void read()
- {
- if(fopen("graph.txt","r")==NULL)cout<<"ERROR\n";
- graph=fopen("graph.txt","r");
- fscanf(graph,"%i",n);
- fscanf(graph,"%i",m);
- ms=new int*[n];
- for(int i=0;i<n;i++) ms[i]=new int[n];
- for(int i=0;i<n;i++)
- for(int j=0;j<n;j++)
- ms[i][j]=0;
- while(!feof(graph))
- {
- fscanf(graph,"%i",v);fscanf(graph,"%i",u);fscanf(graph,"%i",w);
- if (w<0) cout<<"This program can't work right with weight<0";
- else
- ms[v][u]=w;
- }
- //вывод матрицы
- for(int i=0;i<n;i++)
- for(int j=0;j<n;j++)
- cout<<ms[i][j]<<" ";
- cout<<endl;
- }
- void main()
- {
- int key;
- system("cls");
- do{
- cout<<"MENU\n";
- cout<<"1.Read your graph\n";
- cin>>key;
- switch(key)
- {case 1:{ read();break;}
- }
- }while(key!=0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement