60 lines
1 KiB
C
60 lines
1 KiB
C
#include <stdio.h>
|
|
#define MAXLEN 256
|
|
#define SIZE 5
|
|
|
|
int getDigits(int i) {
|
|
int count = 0;
|
|
do {
|
|
i /= 10;
|
|
count++;
|
|
} while (i);
|
|
|
|
return count;
|
|
}
|
|
|
|
int main(void) {
|
|
// remember to initialize to 0
|
|
int matrix[SIZE][SIZE] = {};
|
|
int liked[SIZE][SIZE] = {};
|
|
|
|
char buf[MAXLEN];
|
|
fgets(buf, MAXLEN, stdin);
|
|
int offset = 0;
|
|
int src, dist;
|
|
|
|
while (sscanf(buf + offset, "%d,%d,", &src, &dist) != EOF) {
|
|
// printf("%d -> %d\n", src, dist);
|
|
offset += getDigits(src) + getDigits(dist) + 2;
|
|
matrix[src][dist] = 1;
|
|
}
|
|
|
|
// calculate likes
|
|
for (int i = 0; i < SIZE; i++) {
|
|
int count = 0;
|
|
for (int j = 0; j < SIZE; j++) {
|
|
if (matrix[i][j] == 1) {
|
|
if (++count % 2 == 1) {
|
|
// printf("%d liked %d, count: %d\n", i, j, count);
|
|
liked[i][j] = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
scanf("%d", &dist);
|
|
|
|
int hasLikes = 0;
|
|
for (int i = 0; i < SIZE; i++) {
|
|
if (liked[i][dist] == 1) {
|
|
hasLikes = 1;
|
|
printf("%d,", i);
|
|
}
|
|
}
|
|
|
|
if (!hasLikes) {
|
|
printf("-1");
|
|
}
|
|
|
|
return 0;
|
|
}
|