pta not find common elements of two arrays

Given two integer array, this question is not asked to identify elements common to both.

Input formats:

Two input lines are given in two integer array, each of the first row is given a positive integer N ( ≤), followed by N integers, separated by a space therebetween.

Output formats:

Output in a row in numerical order is not given a total of two array elements, separated by a space between the numbers, but the end of the line can not be redundant space. Title ensure that there is at least one such number. Not repeat the same digital output.

Sample input:

10 3 -5 2 8 0 3 5 -15 9 100
11 6 4 8 2 6 -5 9 0 100 8 1

Sample output:

3 5 -15 6 4 1

#include <stdio.h>
#include <stdlib.h>
int s[100000000] = {0};

int main()
{
    int n, i, j, m, w = 0, flag, q;
    int a[22], b[22];
    scanf("%d", &n);
    for(i = 0; i<n;i++){
        scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    for(i = 0; i<m;i++){
        scanf("%d", &b[i]);
    }
    for(i = 0; i<n; i++){              //先找a中不共有元素
        flag = 1;
        for(j = 0; j<m; j++){
            if(a[i] == b[j]){
                flag = 0;
                break;
            }
        }
        if(flag){
            int flag1 = 1;
            for(Q = 0 ; Q <W; Q ++ ) {
                 IF (A [I] == s [Q]) {         // determines whether this element exists in s 
                    FLAG1 = 0 ;
                     BREAK ; 
                } 
            } 
        IF (FLAG1) s [ W ++] = A [I];        // element is not present, added sequentially 
        } 
    } 
    for (I = 0 ; I <m; I ++) {               // B repeat the seek operation 
        in Flag = . 1 ;
         for (J = 0 ; J <n-; J ++ ) {
             IF (B [I] == A [J]) { 
                In Flag= 0 ;
                 BREAK ; 
            } 
        } 
        IF (In Flag) {
             int FLAG1 = . 1 ;
             for (Q = 0 ; Q <W; Q ++ ) {
                 IF (B [I] == S [Q]) { 
                    FLAG1 = 0 ;
                     BREAK ; 
                } 
            } 
        IF (FLAG1) s [W ++] = B [I]; 
        } 
    } 
    for (Q = 0 ; Q <W; Q ++) {            //S is the output element qualifying 
        the printf ( " % D " , s [Q]);
         IF (! Q = w to . 1 ) the printf ( "  " );
         the else the printf ( " \ n- " ); 
    } 
    return  0 ; 
}

 

 

Guess you like

Origin www.cnblogs.com/kaito77/p/12110155.html