Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let totalTickets = 0;
- let studentTickets = 0;
- let standardTickets = 0;
- let childTickets = 0;
- let index = 0;
- let command;
- while((command = input[index]) !== "Finish") {
- let currentMovie = command;
- index++;
- let totalSeats = Number(input[index]);
- index++;
- let command2;
- let usedSeats = 0;
- while(((command2 = input[index]) !== "End") && totalSeats > usedSeats) {
- let ticketType = command2;
- index++;
- usedSeats++;
- if (ticketType === "student") {
- studentTickets++;
- } else if (ticketType === "standard") {
- standardTickets++;
- } else if (ticketType === "kid") {
- childTickets++;
- }
- }
- console.log(`${currentMovie} - ${((usedSeats)/totalSeats*100).toFixed(2)}% full.`);
- if (command2 === "End") {
- index++;
- }
- }
- totalTickets = studentTickets+standardTickets+childTickets;
- console.log(`Total tickets: ${totalTickets}`);
- console.log(`${(studentTickets/totalTickets*100).toFixed(2)}% student tickets.`);
- console.log(`${(standardTickets/totalTickets*100).toFixed(2)}% standard tickets.`);
- console.log(`${(childTickets/totalTickets*100).toFixed(2)}% kids tickets.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment