Advertisement
NAstra

zad11 Pairs 100/100

Feb 18th, 2023
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getGets = (arr) => {
  2.     let index = 0;
  3.  
  4.     return () => {
  5.         const toReturn = arr[index];
  6.         index += 1;
  7.         return toReturn;
  8.     };
  9.  };
  10.  // This is the place where you must place your test data
  11. const test = [
  12.     '8', // This is the first line from the test.
  13.     '2 4 6 2 4 1 2 3 5 9', // This is the second line from the test.
  14.    
  15.    
  16.  ];
  17.  
  18.  const gets = this.gets || getGets(test);
  19. const print = this.print || console.log;
  20.  
  21. // Solution of the problem. zad2 Pairs 100/100
  22.  
  23. let n = Number(gets());
  24. let array = gets().split(" ").map(Number);
  25. let arr2 = [];
  26.  
  27. for (i = 0; i < array.length; i++) {
  28.   for (y = 0; y < array.length; y++) {
  29.     if ((y > i) && (array[i] + array[y] === n)) {
  30.       arr2.push(array[i], array[y]);
  31.     }
  32.   }
  33. }
  34. if (arr2.length == 0) {
  35.   console.log("no pairs");
  36. } else
  37.   for (z = 0; z < arr2.length; z = z + 2) {
  38.     console.log(`${arr2[z]},${arr2[z + 1]}`);
  39.   }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement