Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; const int mxN = 1e5; void Afisare(int v[]) { for(int i = 1;i<=v[0];i++) cout << v[i] << ' ' ; cout << '\n'; } int* Reuniune(int A[], int B[]) { int* C = new int[2 * mxN + 10]; int it = 0, i = 1, j = 1; while(i <= A[0] && j <= B[0]) { if(A[i] == B[j]) C[++it] = A[i++], j++; else if(A[i] < B[j]) C[++it] = A[i++]; else if(A[i] > B[j]) C[++it] = B[j++]; } while(i <= A[0]) C[++it] = A[i++]; while(j <= B[0]) C[++it] = B[j++]; C[0] = it; return C; } int* Intersectie(int A[], int B[]) { int* C = new int[2 * mxN + 10]; int it = 0, i = 1, j = 1; while(i <= A[0] && j <= B[0]) { if(A[i] == B[j]) C[++it] = A[i++],j++; else if(A[i] < B[j]) i++; else j++; } C[0] = it; return C; } int* Diferenta(int A[], int B[]) { int* C = new int[2 * mxN + 10]; int it = 0, i = 1, j = 1; while(i <= A[0] && j <= B[0]) { if(A[i] == B[j]) i++,j++; else if(A[i] < B[j]) C[++it] = A[i++]; else if(A[i] > B[j]) j++; } while(i <= A[0]) C[++it] = A[i++]; C[0] = it; return C; } int main() { int A[mxN+10] = {0} , B[mxN+10] = {0}; cin >> A[0] >> B[0]; for(int i = 1;i<=A[0];i++) cin >> A[i]; for(int i = 1;i<=B[0];i++) cin >> B[i]; Afisare(Reuniune(A,B)); Afisare(Intersectie(A,B)); Afisare(Diferenta(A,B)); Afisare(Diferenta(B,A)); return 0; } /* INPUT : 4 4 1 2 3 4 3 4 5 6 OUTPUT : 1 2 3 4 5 6 3 4 1 2 5 6 */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)