Advertisement
x2311

Untitled

Jun 15th, 2021
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Богдан Пархоменко
  2.  
  3.  
  4. /*Программа возвращает одну из N тем случайным образом,
  5. и потом эту тему отдавать какому-то человеку
  6. */
  7. function getRandomInt(max) {
  8.     return Math.floor(Math.random() * max);
  9. }
  10.  
  11.  
  12.  
  13. var text = [];
  14.  
  15. for (let i = 0, a = 1; a != 0; i++) {
  16.     console.log("Ведите тему " + (text.length + 1) + ": ")
  17.     a = prompt("Ведите тему (что бы закончить ввод нажмите 0) " + (text.length + 1) + ": ")
  18.     if (a == 0) {
  19.         break;
  20.     }
  21.     text[i] = a;
  22. }
  23. console.log("\n")
  24.  
  25. for (let i = 0; i < text.length; i++) {
  26.     console.log(text[i])
  27. }
  28.  
  29. console.log("\n")
  30.  
  31. var people = [];
  32.  
  33. for (let i = 0, a = 1; a != 0; i++) {
  34.     console.log("Ведите имя человека " + (people.length + 1) + ": ")
  35.     a = prompt("Ведите имя человека (что бы закончить ввод нажмите 0): " + (people.length + 1) + ": ")
  36.     if (a == 0) {
  37.         break;
  38.     }
  39.     people[i] = a;
  40. }
  41. console.log("\n")
  42.  
  43. for (let i = 0; i < people.length; i++) {
  44.     console.log(people[i])
  45. }
  46.  
  47.  
  48. console.log("\n\n\n")
  49. if (text.length >= people.length) {
  50.     for (let c = (people.length), a = 0, b = 0; c != 0;) {
  51.         a = getRandomInt(text.length)
  52.         b = getRandomInt(people.length)
  53.  
  54.  
  55.  
  56.         if (people[b] != 0) {
  57.             console.log(text[a] + " - " + people[b] + "\n")
  58.             console.log()
  59.             people[b] = 0
  60.             c--;
  61.         }
  62.     }
  63. } else {
  64.     for (let c = (people.length), t = 0, a = 0, b = 0; c != 0; a++) {
  65.         // a = getRandomInt(text.length)
  66.         b = getRandomInt(people.length)
  67.         if (t == 1) {
  68.             a = getRandomInt(text.length)
  69.         }
  70.  
  71.  
  72.         if (people[b] != 0) {
  73.             console.log(text[a] + " - " + people[b] + "\n")
  74.             console.log()
  75.             people[b] = 0
  76.             c--;
  77.         }
  78.  
  79.         if (a == text.length - 1) {
  80.             t = 1;
  81.         }
  82.  
  83.     }
  84.  
  85. }
  86.  
  87. console.log("\n\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement