Как построить матрицу инциденций на C++? ​

Ответы

Ответ дал: iskendirizbasar
0

Ответ:

Построить матрицу инцидентности и смежности.

Сформировать множество вершин, из которых исходят ребра заданной стоимости.

Ответ дал: LenivyParenXD
1

Ответ: вот готовый код

#include "stdafx.h"

#include <iostream>

#include <cstdlib>

#include <fstream>

#include <string>

using namespace std;

struct myStruct{  

   char temp[5];  

   int v1;  

   int v2;  

};

 

int main()

{

 

   char filename[50];

   ifstream inFile;

   cout << "Enter the directory of data file:\n";

   cin.getline(filename, 50);

   inFile.open(filename);

 

   if (!inFile.is_open())

   {

       cout << "Can't open the file. Terminating\n";

       exit(EXIT_FAILURE);

   }

 

   char a[5], b[5];

   int n = 0;

   int m = 0;

 

   inFile >> a >> b >> n >> m;

 

   cout << "Number of vertexes is " << n << endl;

   cout << "Number of edges is " << m << endl;

 

 

   myStruct edge[2100];

 

   int i = 0;

 

   while (!inFile.eof())

   {

       inFile >> edge[i].temp >> edge[i].v1 >> edge[i].v2;

       i++;

   }

   

   for (int j = 0; j < m; j++)

   {

       cout << edge[i].temp << " " << edge[i].v1 << " " << edge[i].v2 << " /n";

       j++;

   }

 

   inFile.close();

 

 

   system("pause");

}


artemlis2703: Спасибо
LenivyParenXD: Пожалуйста
Вас заинтересует