【发布时间】:2015-07-29 14:05:02
【问题描述】:
我编写了一个代码来显示两个顶点度数相等的图。但我不知道为什么它不能正常工作并给出不正确的答案。例如:对于两个图,例如:
[0 1 1 0 0 [0 1 0 1 0
1 0 1 0 0 1 0 1 0 0
1 0 0 1 0 0 1 0 1 0
0 0 1 0 1 0 0 1 0 1
0 0 0 1 0] 0 0 0 1 0]
但它不应该写“两个图的顶点度数不同”的消息,而是写它。我不知道该怎么办。 如果可能,请指导我。
int temp = 0;
int temp2 = 0;
int gg = 1;
for (int ia = 0; ia < m; ia++)
{
for (int ja = 0; ja < m; ja++)
{
if (j.f[ia][ja] == 1)
{
temp++;
}
}
for (int i = 0; i < m; i++&&gg == 1)
{
for (int j = 0; j < m; j++&&gg == 1)
{
if (g.f[i][j] == 1)
{
temp2++;
}
}
if (temp == temp2)
gg = 0;
else
{
cout << "two graphs don't have the same degree of vertices";
system("pause");
exit(1);
}
}
【问题讨论】: