Advertisement
Spocoman

Renovation

Feb 13th, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. РЕШЕНИЕ С FOR:
  2.  
  3. function renovation(input) {
  4.     let x = Number(input[0]);
  5.     let y = Number(input[1]);
  6.     let nonPaint = Number(input[2]);
  7.  
  8.     let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
  9.  
  10.     for (let i = 3; i < input.length; i++) {
  11.         let painting = input[i];
  12.         if (painting === "Tired!") {
  13.             break;
  14.         }
  15.         paint -= Number(painting);
  16.         if (paint <= 0) {
  17.             break;
  18.         }
  19.     }
  20.  
  21.     if (paint > 0) {
  22.         console.log(`${paint} quadratic m left.`);
  23.     } else if (paint === 0) {
  24.         console.log("All walls are painted! Great job, Pesho!");
  25.     } else {
  26.         console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
  27.     }
  28. }
  29.  
  30. РЕШЕНИЯ С WHILE:
  31.  
  32. function renovation(input) {
  33.     let index = 0;
  34.     let x = Number(input[index++]);
  35.     let y = Number(input[index++]);
  36.     let nonPaint = Number(input[index++]);
  37.  
  38.     let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
  39.  
  40.     let painting = input[index++];
  41.  
  42.     while (painting !== "Tired!") {
  43.         paint -= Number(painting);
  44.         if (paint <= 0) {
  45.             break;
  46.         }
  47.         painting = input[index++];
  48.     }
  49.  
  50.     if (paint > 0) {
  51.         console.log(`${paint} quadratic m left.`);
  52.     } else if (paint === 0) {
  53.         console.log("All walls are painted! Great job, Pesho!");
  54.     } else {
  55.         console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
  56.     }
  57. }
  58.  
  59. Решение със swift():
  60.  
  61. function renovation(input) {
  62.     let x = Number(input.shift());
  63.     let y = Number(input.shift());
  64.     let nonPaint = Number(input.shift());
  65.  
  66.     let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
  67.  
  68.     let painting = input.shift();
  69.  
  70.     while (painting !== "Tired!") {
  71.         paint -= Number(painting);
  72.         if (paint <= 0) {
  73.             break;
  74.         }
  75.         painting = input.shift();
  76.     }
  77.  
  78.     if (paint > 0) {
  79.         console.log(`${paint} quadratic m left.`);
  80.     } else if (paint === 0) {
  81.         console.log("All walls are painted! Great job, Pesho!");
  82.     } else {
  83.         console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
  84.     }
  85. }
  86.  
  87. Или леко тарикатската със shift() и с тернарен оператор:)
  88.  
  89. function renovation(input) {
  90.     let x = Number(input.shift());
  91.     let y = Number(input.shift());
  92.  
  93.     let paint = x * y * 4 - (x * y * 4 * Number(input.shift()) / 100);
  94.  
  95.     let painting;
  96.  
  97.     while ((painting = input.shift()) !== "Tired!") {
  98.         paint -= Number(painting);
  99.         if (paint <= 0) {
  100.             break;
  101.         }
  102.     }
  103.  
  104.     console.log(paint > 0 ? `${paint} quadratic m left.` :
  105.                 paint === 0 ? "All walls are painted! Great job, Pesho!" :
  106.                 `All walls are painted and you have ${Math.abs(paint)} l paint left!`);
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement