Version Control System Solution || "Mastering Git: Tips and Tricks for Effective Version Control" ||

 Version Control System:

A version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, along with who made the change, why they made it, and references to problems fixed, or enhancements introduced, by the change.

Version control systems are essential for any form of distributed, collaborative development. Whether it is the history of a wiki page or large software development project, the ability to track each change as it was made, and to reverse changes when necessary can make all the difference between a well managed and controlled process and an uncontrolled 'first come, first served' system. It can also serve as a mechanism for due diligence for software projects.

In this problem we'll consider a simplified model of a development project. Let's suppose, that there are N source files in the project. All the source files are distinct and numbered from 1 to N.

A VCS, that is used for maintaining the project, contains two sequences of source files. The first sequence contains the source files, that are ignored by the VCS. If a source file is not in the first sequence, then it's considered to be unignored. The second sequence contains the source files, that are tracked by the VCS. If a source file is not in the second sequence, then it's considered to be untracked. A source file can either be or not be in any of these two sequences.

Your task is to calculate two values: the number of source files of the project, that are both tracked and ignored, and the number of source files of the project, that are both untracked and unignored.


Input

The first line contains three integers N, M and K denoting the number of source files in the project, the number of ignored source files and the number of tracked source files.

The second line contains M distinct integers denoting the sequence A of ignored source files. The sequence is strictly increasing.

The third line contains K distinct integers denoting the sequence B of tracked source files. The sequence is strictly increasing.


Output

Output a single line containing two integers: the number of the source files, that are both tracked and ignored, and the number of the source files, that are both untracked and unignored.


Constraints

• 1 ≤ M, K≤ N ≤ 100

• 1 ≤ A₁ < A2 < ... < Am ≤ N

• 1 ≤ B₁ < B2 < ... < Bk ≤ N


Sample Input:

7 4 6

1 4 6 7

1 2 3 4 6 7


Sample Output:

4 1


Explanation:

The source files {1, 4, 6, 7} are both tracked and ignored, the source file {5} is both untracked and unignored


Sample input 

7 4 6

1 4 6 7

1 2 3 4 6 7


Sample output

4 1




Program:

#C

#include <stdio.h>

int main() {

    int n,m,k;

    scanf("%d %d %d",&n,&m,&k);

    int a[n],b[n],c,d;

for(int i=0;i<n;i++){

a[i]=0,b[i]=0;

}

int q=0;

    for(int i=0;i<n;i++){

if(q<m){

            scanf("%d",&a[i]);

            if(a[i]!=i+1){

        c=a[i];

        a[i]=0;

        i=c-1;

        a[i]=c;

    }

    q++;

        }

}

int lrr=0;

    for(int i=0;i<n;i++){

if(lrr<k){

scanf("%d",&b[i]);

            if(b[i]!=i+1){

d=b[i];

b[i]=0;

i=d-1;

b[i]=d;

}

lrr++;

}

    }

    int count=0,e=0;

    for(int i=0;i<n;i++){

        if(a[i]==b[i] && a[i]>0)

            count++;

        if(a[i]==0 && b[i]==0)

            e++;

    }

    printf("%d %d\n",count,e);

return 0;

}


#Python:

n, m, k = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))

first = len(a.intersection(b))

second = len(set(range(1, n+1)).difference(a.union(b)))

print(f"{first} {second}")




Explanation:

        This code reads three integers n, m, and k from the standard input. It then initializes two integer arrays, a and b, of size n with all elements set to 0. The code then enters a loop that reads in the first m integers into array a. If an integer x is read that is not equal to i+1, where i is the index in the array that we are currently reading into, then it means that the number x should have been at index i+1 in the array. Therefore, we swap a[i] and a[x-1] to get the correct position for x. The loop also increments a counter q to keep track of how many integers have been read into a.

        The code then enters another loop that reads in the next k integers into array b and performs a similar swap operation for each integer if necessary. This loop also increments a counter lrr to keep track of how many integers have been read into b.

        The code then initializes two more counters count and e to 0. It enters another loop that compares the elements of arrays a and b at each index i and increments count if a[i] and b[i] are equal and greater than 0. The loop also increments e if a[i] and b[i] are both 0.

        Finally, the code prints out count and e separated by a space. The purpose of the code seems to be to read in two permutations of integers, represented by arrays a and b, and count the number of positions where the two permutations have the same integer value, as well as the number of positions where both arrays have a 0 value.

Post a Comment

0 Comments