Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- const int SIZE_LIMIT = 16;
- ofstream output;
- void matrix_display(bool graph[SIZE_LIMIT][SIZE_LIMIT], int nodes_count)
- {
- for (int i = 0; i < nodes_count; i++) {
- for (int j = 0; j < nodes_count; j++) {
- output << graph[i][j] << ' ';
- }
- output << endl;
- }
- }
- /**
- * Получить список вершин, у которых число входов больше чем число выходов
- */
- void show_filtred_nodes(bool graph[SIZE_LIMIT][SIZE_LIMIT], int nodes_count){
- int in_count, out_count;
- output << "--------------------------------------------------------------" << endl;
- output << "Список вершин, у которых число входов больше чем число выходов" << endl;
- for (int i = 0; i < nodes_count; i++) {
- in_count = out_count = 0;
- for (int j = 0; j < nodes_count; j++) {
- if (graph[i][j])
- out_count++;
- }
- for (int j = 0; j < nodes_count; j++) {
- if (graph[j][i])
- in_count++;
- }
- if (in_count > out_count){
- output << (i + 1) << endl;
- }
- }
- }
- int main()
- {
- ifstream input("input.in");
- bool graph[SIZE_LIMIT][SIZE_LIMIT] = {0};
- output.open("output.out");
- int from, to, max_node=0;
- while (input >> from >> to) {
- if (max_node < to)
- max_node = to;
- if (max_node < from)
- max_node = from;
- if ((SIZE_LIMIT < from) || (SIZE_LIMIT < to)){
- output << "Количество вершин графа должно быть не более " << SIZE_LIMIT << endl;
- exit(0);
- }
- graph[from-1][to-1] = 1;
- }
- input.close();
- output << "--------------------------------------------------------------" << endl;
- output << "Количество вершин: " << max_node << endl;
- output << "--------------------------------------------------------------" << endl;
- output << "Матрица смежности:" << endl;
- matrix_display(graph, max_node);
- show_filtred_nodes(graph, max_node);
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment