ErolKZ

Untitled

Jul 13th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let countFloors = Number(input[0]);
  4.  
  5. let countRoomsForOneFloor = Number(input[1]);
  6.  
  7. let apartment = '';
  8.  
  9. let office = '';
  10.  
  11. let large = '';
  12.  
  13.  
  14. for (let i = countFloors; 1 <= i; i--) {
  15.  
  16.  
  17.  
  18. for (let j = 0; j < countRoomsForOneFloor; j++) {
  19.  
  20. if (i % 2 === 0 && i !== countFloors) {
  21.  
  22. if (j !== countRoomsForOneFloor - 1) {
  23.  
  24. office += `O${i}${j}` + ' ';
  25.  
  26. } else {
  27.  
  28. office += `O${i}${j}`;
  29.  
  30. }
  31.  
  32.  
  33.  
  34. } else if (i % 2 !== 0 && i !== countFloors) {
  35.  
  36. if (j !== countRoomsForOneFloor - 1) {
  37.  
  38. apartment += `A${i}${j}` + ' ';
  39.  
  40. } else {
  41.  
  42. apartment += `A${i}${j}`;
  43.  
  44. }
  45.  
  46.  
  47. } else {
  48.  
  49. if (j !== countRoomsForOneFloor - 1) {
  50.  
  51. large += `L${i}${j}` + ' ';
  52.  
  53. } else {
  54.  
  55. large += `L${i}${j}`;
  56.  
  57. }
  58.  
  59. }
  60.  
  61. if (j === countRoomsForOneFloor - 1 && (apartment !== '' || office !== '' || large !== '')) {
  62.  
  63.  
  64. console.log(`${large}${office}${apartment}`);
  65.  
  66.  
  67.  
  68.  
  69. office = '';
  70.  
  71. apartment = '';
  72.  
  73. large = '';
  74.  
  75. }
  76.  
  77.  
  78.  
  79. } // Inner loop
  80.  
  81.  
  82.  
  83.  
  84. } // Outer loop
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment