Dev - C++ - Dev - C++ - cambiar cout a printf en c++.

 
Vista:
sin imagen de perfil

Dev - C++ - cambiar cout a printf en c++.

Publicado por bastian (12 intervenciones) el 11/10/2021 19:29:32
Hola,

Amigos me podrían colaborar, requiero cambiar el cout por printf del siguiente programa,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <climits>
#include <iomanip>
using namespace std;
#define N 6
#define M INT_MAX
void printPath(int path[][N], int v, int u)
{
    if (path[v][u] == v)
        return;
 
    printPath(path, v, path[v][u]);
    cout << path[v][u] << " ";
}
void printSolution(int cost[N][N], int path[N][N])
{
    for (int v = 0; v < N; v++)
    {
        for (int u = 0; u < N; u++)
        {
            if (u != v && path[v][u] != -1)
            {
                cout << "Shortest Path from " << v << " -> " << u << " is ("
                     << v << " ";
                printPath(path, v, u);
                cout << u << ")" << endl;
            }
        }
    }
}
 
void floydWarshall(int adjMatrix[][N])
{
    int cost[N][N], path[N][N];
    for (int v = 0; v < N; v++)
    {
        for (int u = 0; u < N; u++)
        {
            cost[v][u] = adjMatrix[v][u];
 
            if (v == u)
                path[v][u] = 0;
            else if (cost[v][u] != INT_MAX)
                path[v][u] = v;
            else
                path[v][u] = -1;
        }
    }
 
    for (int k = 0; k < N; k++)
    {
        for (int v = 0; v < N; v++)
        {
            for (int u = 0; u < N; u++)
            {
                if (cost[v][k] != INT_MAX && cost[k][u] != INT_MAX
                    && cost[v][k] + cost[k][u] < cost[v][u])
                {
                    cost[v][u] = cost[v][k] + cost[k][u];
                    path[v][u] = path[k][u];
                }
            }
 
            if (cost[v][v] < 0)
            {
                cout << "Negative Weight Cycle Found!!";
                return;
            }
        }
    }
    printSolution(cost, path);
}
 
int main()
{
    int adjMatrix[N][N] =
    {
             {0, 3, 2, M, 1, M},
             {3, 0, M, 4, M, M},
             {2, M, 0, M, 3, 1},
             {M, 4, M, 0, M, 2},
	     {1, M, 3, M, 0, 5},
	     {M, M, 1, 2, 5, 0}
    };
    floydWarshall(adjMatrix);
 
    return 0;
}

He realizado varios intentos pero no he logrado que me compile correctamente.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder