Professional Documents
Culture Documents
Laboratorul 1 La Disciplina Algoritmica Grafurilor: Facultatea Tehnologii Informaționale Și Statistică Economică
Laboratorul 1 La Disciplina Algoritmica Grafurilor: Facultatea Tehnologii Informaționale Și Statistică Economică
Laboratorul 1
La disciplina Algoritmica grafurilor
Student:
Tacic Vasile
Grupa: TI-181
Chişinău 2020
Item 1
C++ Script
#include <iostream>
#include <fstream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int n, A[NMax][NMax];
int n, m, x,y;
ifstream f("graf.in");
ofstream g("matricea.out");
f>>n>>m;
while (m--)
f>>x>>y;
A[x][y]=A[y][x]=1;
int i=1;
while(i<=n)
{ int j=1;
while(j<=n){
g<<A[i][j]<<" ";
//cout<<A[i][j];
j++;
g<<endl;
i++;
g.close();
f.close();
Fisierul Graf.in
88
12
23
34
45
56
67
78
Fisierul Matrice.out
01000000
10100000
01010000
00101000
00010100
00001010
00000101
00000010
Item 2
C++ Script
#include <iostream>
#include <fstream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int n, A[NMax][NMax];
int n, m, x,y;
ifstream f("graf.in");
ofstream g("matricea.out");
f>>n>>m;
while (m--)
f>>x>>y;
A[x][y]=1;
int i=1;
while(i<=n)
{ int j=1;
while(j<=n){
g<<A[i][j]<<" ";
//cout<<A[i][j];
j++;
g<<endl;
i++;
g.close();
f.close();
Graf.in
8
12
23
34
45
56
67
78
81
Matrice.out
01000000
00100000
00010000
00001000
00000100
00000010
00000001
10000000
Item 3
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
int n;
int * A[NMax];
void citire();
void afisare();
citire();
afisare();
return 0;
void citire() {
int x, y, m, i;
A[i][0]=0;}
A[x][0]++;
A[x][A[x][0]]=y;
A[y][0]++;
A[y]=(int *)realloc(A[y], (A[y][0]+1)*sizeof(int));
A[y][A[y][0]]=x;
void afisare() {
int i, j;
printf("\n");
Date de intrare
Graf.in
8
12
23
34
45
56
67
78
81
Date de iesire
Item 4
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
int n;
int * A[NMax];
void citire();
void afisare();
citire();
afisare();
return 0;
void citire() {
int x, y, m, i;
A[i][0]=0;}
A[x][0]++;
A[x][A[x][0]]=y;
void afisare() {
int i, j;
printf("\n");
Date de intrare
Graf.in
8
12
23
34
45
56
67
78
81
Date de iesrire