A version Management system (VMS) 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.
In this problem we will 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 VMS which is used for maintaining the project contains two sequences of source files. The first sequence contains M source files that are ignored by the VMS. If a source file is not in the first sequence, then it’s considered to be unignored. The second sequence contains K source files that are tracked by the VMS. 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 Format:
The first line of the input 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. Assume that the maximum value for N as 50.
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 Format:
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.
Refer sample input and output for formatting specifications.
Sample Input 1:
7 4 6
1 4 6 7
1 2 3 4 6 7
Sample Output 1:
4 1
Sample Input 2:
4 2 2
1 4
3 4
Sample Output 2:
1 1
Solution
import java.util.*;
import java.util.stream.IntStream;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int count =0,count1 =0;
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
int arr1[]=new int[n];
//sauravhathi
int arr2[]=new int[n];
for(int i=0;i<m;i++)
arr1[i] = sc.nextInt();
for(int i=0;i<k;i++)
arr2[i] = sc.nextInt();
for(int p=1;p<=n;p++)
{
int op=p;
if(IntStream.of(arr1).anyMatch(x -> x == op)&&IntStream.of(arr2).anyMatch(x -> x == op))
count++;
if(!(IntStream.of(arr1).anyMatch(x -> x == op))&&!(IntStream.of(arr2).anyMatch(x -> x == op)))
count1++;
}
System.out.println(count+" "+count1);
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M, K;
cin >> N >> M >> K;
//sauravhathi
vector<int> v(M), v1(K);
map<int, int> m;
for (int i = 0; i < M; i++)
{
int x;
cin >> x;
v.push_back(x);
}
for (int i = 0; i < K; i++)
{
int y;
cin >> y;
v1.push_back(y);
}
for (int i = 0; i < v.size(); i++)
{
m[v[i]]++;
}
for (int i = 0; i < v1.size(); i++)
{
m[v1[i]]++;
}
int count = 0, count1 = 0;
//sauravhathi
for (int i = 0; i <= N; i++)
{
if (m[i] == 2)
{
count++;
}
else if (m[i] == 0)
{
count1++;
}
}
cout << count << " " << count1 << endl;
return 0;
//sauravhathi
}
N = int(input())
M = int(input())
K = int(input())
v = list(map(int, input().split()))
v1 = list(map(int, input().split()))
m = {}
for i in v:
m[i] = 1
for i in v1:
m[i] = 1
count = 0
count1 = 0
for i in range(1, N+1):
if m[i] == 2:
count += 1
elif m[i] == 0:
count1 += 1
print(count, count1)
Happy Learning – If you require any further information, feel free to contact me.