Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let cleaningStuff = input.shift();
- let cleaningStuffQ = cleaningStuff * 750;
- let sumOfWashes = 0;
- let plate = 0;
- let pots = 0;
- let counter = 1;
- // за 1 чиния са нужни 5 мл., а за тенджера 15 мл
- while (true) {
- let command = input.shift();
- if (command === "End") {
- break;
- }
- if (counter % 3 == 0) {
- sumOfWashes += command * 15;
- } else {
- sumOfWashes += command * 5;
- }
- if (sumOfWashes > cleaningStuffQ) {
- break;
- }
- if (counter % 3 ==0){
- pots += Number(command);
- }else {
- plate +=Number(command);
- }
- counter++;
- }
- if (cleaningStuffQ>= sumOfWashes){
- console.log("Detergent was enough!");
- console.log(`${plate} dishes and ${pots} pots were washed.`);
- console.log(`Leftover detergent ${cleaningStuffQ-sumOfWashes} ml.`);
- }else {
- console.log(`Not enough detergent, ${Math.abs(cleaningStuffQ-sumOfWashes)} ml. more necessary!`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement