fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX = 10001;
  5.  
  6. void intersection3(int a[MAX], int b[MAX], int result[MAX]) {
  7. int howMany = 0, c[1000000];
  8. for (int i = 1; i <= a[0]; ++i) {
  9. ++c[a[i]];
  10. }
  11. for (int i = 1; i <= b[0]; ++i) {
  12. if (c[b[i]] > 0) {
  13. ++howMany;
  14. result[howMany] = b[i];
  15. --c[b[i]];
  16. }
  17. }
  18. result[0] = howMany;
  19. for (int i = 0; i <= howMany; ++i) {
  20. cout << result[i];
  21. }
  22. return;
  23. }
  24. int main() {
  25. int a[] = {5, 1, 2, 2, 5, 8}, b[] = {6, 6, 6, 6, 6, 6, 6}, result[MAX];
  26. intersection3(a, b, result);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty