1 solutions
-
0
憨憨做法,有优解call 我
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int A[10005] , B[10005] , C[10005] , D[10005] , E[10005]; int n , m; cin >> n; for(int i = 1 ;i <= n ;i++) { cin >> A[i]; D[i] = A[i]; } cin >> m; for(int i = 1 ;i <= m ;i++){ cin >> B[i]; } int s = 0; for(int i = 1 ;i <= n ;i++){ for(int j = 1 ;j <= m ;j++){ if(A[i] == B[j]){ s++; C[s] = A[i];//交集 } } } sort(C + 1 , C + 1 + s); int o = n; int ju = 1; for(int i = 1 ;i <= m ;i++){ for(int j = 1 ;j <= n ;j++){ if(B[i] == A[j]){ ju = 0; continue; } } if(ju == 1){ o++; D[o] = B[i]; } ju = 1; } sort(D + 1 , D + o + 1); int flag = 1; int w = 0; for(int i = 1 ;i <= n ;i++){ for(int j = 1 ;j <= m ;j++){ if(A[i] == B[j]){ flag = 0; continue; } } if(flag == 1){ w++; E[w] = A[i]; } flag = 1; } sort(E + 1 , E + 1 + w); for(int i = 1 ;i <= s ;i++){ cout << C[i] << " "; } cout << "\n"; for(int i = 1 ;i <= o ;i++){ cout << D[i] << " "; } cout << "\n"; for(int i = 1 ;i <= w ;i++){ cout << E[i] << " "; } return 0; }
- 1
Information
- ID
- 1739
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By