ErolKZ

Untitled

Jun 27th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. function solve(input) {
  2.  
  3.  
  4. let vaucherValue = Number(input[0]);
  5.  
  6. let prize = 0;
  7.  
  8. let tickets = 0;
  9.  
  10. let others = 0;
  11.  
  12.  
  13.  
  14. for (let i = 1; i < input.length; i++) {
  15.  
  16.  
  17. if (input[i] !== 'End') {
  18.  
  19. if (input[i].length > 8) {
  20.  
  21. prize = input[i].charCodeAt(0) + input[i].charCodeAt(1);
  22.  
  23. if (prize < vaucherValue) {
  24.  
  25. vaucherValue = vaucherValue - prize;
  26. tickets += 1;
  27. }
  28.  
  29.  
  30. } else if (input[i].length <= 8) {
  31.  
  32. prize = input[i].charCodeAt(0);
  33.  
  34. if (prize < vaucherValue) {
  35.  
  36. vaucherValue = vaucherValue - prize;
  37. others += 1;
  38.  
  39. }
  40.  
  41.  
  42.  
  43. }
  44.  
  45. } else {
  46.  
  47. break;
  48.  
  49. }
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. console.log(tickets);
  59. console.log(others);
  60.  
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment