Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С FOR:
- function renovation(input) {
- let x = Number(input[0]);
- let y = Number(input[1]);
- let nonPaint = Number(input[2]);
- let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
- for (let i = 3; i < input.length; i++) {
- let painting = input[i];
- if (painting === "Tired!") {
- break;
- }
- paint -= Number(painting);
- if (paint <= 0) {
- break;
- }
- }
- if (paint > 0) {
- console.log(`${paint} quadratic m left.`);
- } else if (paint === 0) {
- console.log("All walls are painted! Great job, Pesho!");
- } else {
- console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
- }
- }
- РЕШЕНИЯ С WHILE:
- function renovation(input) {
- let index = 0;
- let x = Number(input[index++]);
- let y = Number(input[index++]);
- let nonPaint = Number(input[index++]);
- let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
- let painting = input[index++];
- while (painting !== "Tired!") {
- paint -= Number(painting);
- if (paint <= 0) {
- break;
- }
- painting = input[index++];
- }
- if (paint > 0) {
- console.log(`${paint} quadratic m left.`);
- } else if (paint === 0) {
- console.log("All walls are painted! Great job, Pesho!");
- } else {
- console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
- }
- }
- Решение със swift():
- function renovation(input) {
- let x = Number(input.shift());
- let y = Number(input.shift());
- let nonPaint = Number(input.shift());
- let paint = x * y * 4 - (x * y * 4 * nonPaint / 100);
- let painting = input.shift();
- while (painting !== "Tired!") {
- paint -= Number(painting);
- if (paint <= 0) {
- break;
- }
- painting = input.shift();
- }
- if (paint > 0) {
- console.log(`${paint} quadratic m left.`);
- } else if (paint === 0) {
- console.log("All walls are painted! Great job, Pesho!");
- } else {
- console.log(`All walls are painted and you have ${Math.abs(paint)} l paint left!`);
- }
- }
- Или леко тарикатската със shift() и с тернарен оператор:)
- function renovation(input) {
- let x = Number(input.shift());
- let y = Number(input.shift());
- let paint = x * y * 4 - (x * y * 4 * Number(input.shift()) / 100);
- let painting;
- while ((painting = input.shift()) !== "Tired!") {
- paint -= Number(painting);
- if (paint <= 0) {
- break;
- }
- }
- console.log(paint > 0 ? `${paint} quadratic m left.` :
- paint === 0 ? "All walls are painted! Great job, Pesho!" :
- `All walls are painted and you have ${Math.abs(paint)} l paint left!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement