summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-03-29 12:54:55 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-03-29 12:54:55 +0400
commit0e0a92224c663a1ce224455673a7a022a2b1f790 (patch)
tree84fa9144b1a38488f4eaf3ca71af0537f0edb00f
parentf29b59c5244703475d2925dc6f8e9a63c982536d (diff)
Добавил 5 задачу в графах
-rw-r--r--graphs/Makefile3
-rw-r--r--graphs/task9_1.cpp58
2 files changed, 59 insertions, 2 deletions
diff --git a/graphs/Makefile b/graphs/Makefile
index bde760b..1441a5f 100644
--- a/graphs/Makefile
+++ b/graphs/Makefile
@@ -22,8 +22,7 @@ test12_1: task12_1
task9_1:
$(COMPILE) -o task.out task9_1.cpp
test9_1: task9_1
- @printf "" | ./task.out
- @printf "Answer: \n"
+ @printf "4\n5\n1 2\n1 3\n1 4\n2 3\n3 4" | ./task.out
task5_2:
$(COMPILE) -o task.out task5_2.cpp
diff --git a/graphs/task9_1.cpp b/graphs/task9_1.cpp
new file mode 100644
index 0000000..c3077cf
--- /dev/null
+++ b/graphs/task9_1.cpp
@@ -0,0 +1,58 @@
+#include<iostream>
+#include<stdio.h>
+#include<vector>
+
+using namespace std;
+
+typedef vector<vector<int>> graph;
+
+void print(graph g)
+{
+ for (int i = 0; i < int(g.size()); ++i)
+ {
+ cout << i + 1 << ": ";
+ for (auto node : g[i])
+ cout << node + 1 << ", ";
+ cout << endl;
+ }
+
+}
+
+int main()
+{
+ cout << "Введите количество вершин: ";
+ int n;
+ cin >> n;
+
+ cout << "Введите количество рёбер: ";
+ int k;
+ cin >> k;
+
+ graph g(n);
+
+ cout << "o----------------------o" << endl;
+ cout << "| Нумерация вершин с 1 |" << endl;
+ cout << "o----------------------o" << endl;
+
+ cout << "Введите рёбра (неориентированные):" << endl;
+ for (int i = 0; i < k; ++i)
+ {
+ int a, b;
+ cin >> a >> b;
+ a--;
+ b--;
+ g[a].push_back(b);
+ g[b].push_back(a);
+ }
+
+ cout << "Введённый граф:" << endl;
+ print(g);
+
+ cout << "Степени каждой из вершин:" << endl;
+ for (int i = 0; i < int(g.size()); ++i)
+ {
+ printf("d(%i) = %i\n", i + 1, int(g[i].size()));
+ }
+
+ return 0;
+}