Write an algorithm to count the number of elements that are not common to each list.

0

The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in case of syntax/runtime error. The version of GCC being used is 5.5.0.

You are given two lists of different lengths of positive integers. 

Write an algorithm to count the number of elements that are not common to each list.

Write an algorithm to count the number of elements that are not common to each list.
Write an algorithm to count the number of elements that are not common to each list.

Output

Print a positive integer representing the count of elements that are not common to both the lists of integers.

Example

Input

11
1 1 2 3 4 5 5 7 6 9 10
10
11 12 13 4 5 6 7 18 19 20

Output

12

Explanation

The numbers that are not common to both lists are [1, 1, 2, 3, 9, 10, 11, 12, 13, 18, 19, 20].

Output

12
👇Programming language is C👇
#include 

int main() {
    int n1, n2;
    scanf("%d", &n1);
    int a[n1];
    for (int i = 0; i < n1; i++) {
        scanf("%d", &a[i]);
    }
    scanf("%d", &n2);
    int b[n2];
    for (int i = 0; i < n2; i++) {
        scanf("%d", &b[i]);
    }
    int count = 0;
    for (int i = 0; i < n1; i++) {
        int flag = 0;
        for (int j = 0; j < n2; j++) {
            if (a[i] == b[j]) {
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            count++;
        }
    }
    for (int i = 0; i < n2; i++) {
        int flag = 0;
        for (int j = 0; j < n1; j++) {
            if (b[i] == a[j]) {
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

Tags

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !