Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- long long int remove_duplicate(long long int a[], long long int n){
- long long int i, j = 0;
- for(i = 0; i < n-1; i++){
- if(a[i] != a[i+1]){
- a[j++] = a[i];
- }
- }
- a[j++] = a[n-1];
- return j;
- }
- int main(){
- int t; cin >> t;
- while(t--){
- long long int n1, n2, n3; cin >> n1 >> n2 >> n3;
- long long int a[n1], b[n2], c[n3], i;
- // Taking input
- for(i = 0; i < n1; i++) cin >> a[i];
- for(i = 0; i < n2; i++) cin >> b[i];
- for(i = 0; i < n3; i++) cin >> c[i];
- n1 = remove_duplicate(a, n1);
- n2 = remove_duplicate(b, n2);
- n3 = remove_duplicate(c, n3);
- // Show array
- /*
- for(i = 0; i < n1; i++) cout << a[i] << ' ';
- cout << endl;
- */
- long long int j = 0, k = 0, flag = 1; i = 0;
- while(i < n1 && j < n2 && k < n3){
- if(a[i] == b[j] && b[j] == c[k]){
- cout << a[i] << ' ';
- i++; j++; k++;
- flag = 0;
- }
- if(a[i] < b[j]) i++;
- else if(b[j] < c[k]) j++;
- else k++;
- }
- if(flag) cout << "-1";
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment