Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let movieName=input[0];
- let totspace=1;
- let index=1;
- let type=input[index];
- let standcount=0;
- let kidcount=0;
- let studcount=0;
- let totcount=0;
- let totcountFin=0;
- let att=0;
- let fullcount=0;
- while (type!=="Finish") {
- if (fullcount==totspace && type!= "End") {
- index++;
- type=input[index];
- continue;
- }
- if (type==="End") {
- att=(totcount/totspace*100).toFixed(2);
- console.log(`${movieName} - ${att}% full.`);
- totcountFin+=totcount;
- totcount=0;
- fullcount=0;
- index++;
- type=input[index];
- } else if (!isNaN(type)) {
- totspace= Number(type);
- index++;
- type=input[index];
- } else if (type==="standard") {
- standcount++;
- index++;
- type=input[index];
- totcount++;
- fullcount++;
- } else if (type==="student") {
- studcount++
- index++;
- type=input[index];
- totcount++;
- fullcount++;
- } else if (type==="kid") {
- kidcount++
- index++;
- type=input[index];
- totcount++;
- fullcount++;
- } else {
- movieName= type;
- index++;
- type=input[index];
- }
- }
- totcountFin+=totcount;
- att=(totcount/totspace*100).toFixed(2);
- console.log(`${movieName} - ${att}% full.`);
- let perkid=(kidcount/totcountFin*100).toFixed(2);
- let perstud=(studcount/totcountFin*100).toFixed(2);
- let perstand=(standcount/totcountFin*100).toFixed(2);
- console.log (`Total tickets: ${totcountFin}`);
- console.log (`${perstud}% student tickets.`);
- console.log (`${perstand}% standard tickets.`);
- console.log (`${perkid}% kids tickets.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement