#include #include #include #include struct node { struct node *next; int data; }; // Given two linked lists, // count the number of nodes at the same index in both lists // which their values are divisible by 5 // For example: // 2->1->40->X // 1->2->30->4->100->X // Would print out 1 // because both 40 and 30 at the same index (2) are divisible by 5 int count_divisible(struct node *head1, struct node *head2) { // PUT YOUR CODE HERE struct node *tmp1 = head1; struct node *tmp2 = head2; int count = 0; while (tmp1 != NULL && tmp2 != NULL) { if (tmp1->data % 5 == 0 && tmp2->data % 5 == 0) { count++; } tmp1 = tmp1->next; tmp2 = tmp2->next; } return count; } struct node *strings_to_list(int len, char *strings[]); // DO NOT CHANGE THIS MAIN FUNCTION int main(int argc, char *argv[]) { // create two linked lists from command line arguments int dash_arg = argc - 1; while (dash_arg > 0 && strcmp(argv[dash_arg], "-") != 0) { dash_arg = dash_arg - 1; } struct node *head1 = strings_to_list(dash_arg - 1, &argv[1]); struct node *head2 = strings_to_list(argc - dash_arg - 1, &argv[dash_arg + 1]); printf("%d\n", count_divisible(head1, head2)); return 0; } // DO NOT CHANGE THIS FUNCTION // create linked list from array of strings struct node *strings_to_list(int len, char *strings[]) { struct node *head = NULL; for (int i = len - 1; i >= 0; i = i - 1) { struct node *n = malloc(sizeof (struct node)); assert(n != NULL); n->next = head; n->data = atoi(strings[i]); head = n; } return head; }