#include <iostream>
using namespace std;
#include <cstdio>
void rela(int n){
int people[n][n];
// 初始化关系矩阵,自己的位置填入-1,其余为0
for(int i=0;i<n;++i){
for (int j = 0; j < n; ++j){
if (i==j){
people[i][j] = -1;
} else{
people[i][j] = 0;
}}}
// 将输入的有朋友关系的位置改为数值1
while(1){
int a = 0, b =-2;
scanf(",(%d,%d)", &a, &b);
if (b == -2)break;
else {
people[a - 1][b - 1] = 1;
people[b - 1][a - 1] = 1;
}}
// 判断关系
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
//位置为0的地方有朋友的朋友和其他情况
if (people[i][j]==0){
//筛选出朋友的朋友并输出结果
for (int k = 0; k < n; ++k) {
if (people[i][k] &#
已知某班级社会网络,共有n个同学,即a1,a2,…,an。当给定n,以及部分同学之间的朋友关系,试给出哪些同学与他们的朋友的朋友之间没有关系。
最新推荐文章于 2025-06-03 18:45:36 发布