icp/oer/courses/c-advanced/sections/01-introduction/07-graphs/solution.c

43 lines
698 B
C

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
// NOTE: These are the nodes
char *Names[5] =
{
"Mike",
"Bob",
"Anna",
"Emma",
"Nick"
};
// NOTE: These are the edges
// for now everyone can only like two other people
int Likes[5][2] =
{
{1,3}, // Mike likes Bob and Emma
{4,3},
{0,4},
{2,4},
{1,2}
};
// TODO: print out everyone, who likes one, which likes them back
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 2; j++)
{
int iLikes = Likes[i][j];
for(int k = 0; k < 2; k++)
{
if(Likes[iLikes][k] == i)
{
printf("%s and %s both like each other.\n", Names[i], Names[iLikes]);
}
}
}
}
}