代码:
/** *作者:魏宝航 *2020年11月30日,下午21:22 */ #include<iostream> using namespace std; class Graphic { public: char vexs[999]; int graphic[999][999]; int num; Graphic(char vexs[], int edges[][3],int n) { num = n; for (int i = 0; i < n; i++) { this->vexs[i] = vexs[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (edges[i][j] == 0&&i!=j) { graphic[i][j] = INT_MAX; } else { graphic[i][j] = edges[i][j]; } } } } void print() { for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { if (graphic[i][j] == INT_MAX) { cout << '∞' << " "; } else { cout << graphic[i][j] << " "; } } cout << endl; } } }; int main() { int arr[3][3] = { {0,2,3},{4,0,6},{7,8,0} }; char vex[3] = { 'A','B','C' }; Graphic* g = new Graphic(vex,arr,3); g->print(); }