Last active
January 8, 2023 15:06
-
-
Save kijamve/30d0fa6133aa4ba85647bb6d35aaeaa6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<cstring> | |
// Aqui explicamos este algoritmo: https://www.youtube.com/watch?v=MpwbRV6lzR0 | |
// Aprende a usar Grafos en C/C++ 😎 FACILITO 😁 y con Matriz de Adyacencia | |
// Con esta macro transformamos un caracter ASCII A-Z a un entero de 0-25. | |
// Sin importar que este en mayusculas o minusculas. | |
// IMPORTANTE: Este algoritmo no soporta acentos ni la letra ñ!... | |
#define C(x) ( x > 'Z' ? x-'a' : x-'A' ) | |
int main() { | |
unsigned int matrix[26][26], w; | |
char u, v; | |
//Inicializamos la Matrix en 0 | |
memset(matrix, 0, sizeof(matrix)); | |
//freopen Redirecciona la entrada STD desde un archivo | |
if(freopen("input.txt", "r", stdin) == NULL) { | |
printf("File not found..."); | |
return -1; | |
} | |
while(scanf("%c %c %u\n", &u, &v, &w) == 3) { | |
matrix[C(u)][C(v)] = w; | |
} | |
// En este punto tenemos cargada la matriz de adyacencia en "matrix"... | |
if (matrix[C('b')][C('c')]) { | |
printf("Hay un camino de B hacia C y pesa: %u.\n", matrix[C('b')][C('c')]); | |
} else { | |
printf("No existe un camino de B hacia C.\n"); | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A C 4 | |
B A 5 | |
B C 7 | |
C B 9 | |
D A 1 | |
D D 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"configurations": [ | |
{ | |
"name": "(gdb) Iniciar", | |
"type": "cppdbg", | |
"request": "launch", | |
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe", | |
"args": [], | |
"stopAtEntry": false, | |
"cwd": "${fileDirname}", | |
"environment": [], | |
"externalConsole": false, | |
"MIMode": "gdb", | |
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", | |
"setupCommands": [ | |
{ | |
"description": "Habilitar la impresión con sangría para gdb", | |
"text": "-enable-pretty-printing", | |
"ignoreFailures": true | |
}, | |
{ | |
"description": "Establecer tipo de desensamblado en Intel", | |
"text": "-gdb-set disassembly-flavor intel", | |
"ignoreFailures": true | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment