Advertisement
Guest User

Untitled

a guest
May 18th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let movieName=input[0];
  4. let totspace=1;
  5. let index=1;
  6. let type=input[index];
  7. let standcount=0;
  8. let kidcount=0;
  9. let studcount=0;
  10. let totcount=0;
  11. let totcountFin=0;
  12. let att=0;
  13. let fullcount=0;
  14.  
  15.  
  16. while (type!=="Finish") {
  17. if (fullcount==totspace && type!= "End") {
  18. index++;
  19. type=input[index];
  20. continue;
  21. }
  22. if (type==="End") {
  23. att=(totcount/totspace*100).toFixed(2);
  24. console.log(`${movieName} - ${att}% full.`);
  25. totcountFin+=totcount;
  26. totcount=0;
  27. fullcount=0;
  28. index++;
  29. type=input[index];
  30.  
  31. } else if (!isNaN(type)) {
  32. totspace= Number(type);
  33. index++;
  34. type=input[index];
  35. } else if (type==="standard") {
  36. standcount++;
  37. index++;
  38. type=input[index];
  39. totcount++;
  40. fullcount++;
  41. } else if (type==="student") {
  42. studcount++
  43. index++;
  44. type=input[index];
  45. totcount++;
  46. fullcount++;
  47. } else if (type==="kid") {
  48. kidcount++
  49. index++;
  50. type=input[index];
  51. totcount++;
  52. fullcount++;
  53. } else {
  54. movieName= type;
  55. index++;
  56. type=input[index];
  57. }
  58.  
  59.  
  60. }
  61. totcountFin+=totcount;
  62. att=(totcount/totspace*100).toFixed(2);
  63. console.log(`${movieName} - ${att}% full.`);
  64.  
  65. let perkid=(kidcount/totcountFin*100).toFixed(2);
  66. let perstud=(studcount/totcountFin*100).toFixed(2);
  67. let perstand=(standcount/totcountFin*100).toFixed(2);
  68.  
  69. console.log (`Total tickets: ${totcountFin}`);
  70. console.log (`${perstud}% student tickets.`);
  71. console.log (`${perstand}% standard tickets.`);
  72. console.log (`${perkid}% kids tickets.`);
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement