Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let NumberAstrounafts=Number(input.shift());
- let AllAstrounafts={};
- for (let i = 0; i < NumberAstrounafts; i++) {
- let [name,oxigen, energy]=input[i].split(' ');
- AllAstrounafts[name]={oxigen:Number(oxigen), energy:Number(energy)};
- }
- for (let j = 0; j <NumberAstrounafts; j++) {
- input.shift();
- }
- let FirstLine= input.shift();
- while(FirstLine !='End'){
- const [cmd,name,typeneede]= FirstLine.split(' - ');
- switch(cmd){
- case 'Explore':
- let needeenergy=Number(typeneede);
- if(AllAstrounafts[name].energy >= needeenergy){
- AllAstrounafts[name].energy -=needeenergy;
- let currentenergy=AllAstrounafts[name].energy ;
- console.log(`${name} has successfully explored a new area and now has ${currentenergy} energy!`)
- }
- else{
- console.log(`${name} does not have enough energy to explore!`)
- }
- break;
- case 'Refuel':
- let amount= Number(typeneede);
- let lastnergy=0;
- if(AllAstrounafts[name].energy <200){
- lastnergy=200-AllAstrounafts[name].energy;
- if(lastnergy <amount){
- amount=lastnergy;
- }
- AllAstrounafts[name].energy +=amount;
- if( AllAstrounafts[name].energy >200){
- AllAstrounafts[name].energy=200;
- }
- console.log(`${name} refueled their energy by ${amount}!`)
- }
- break;
- case 'Breathe':
- let amount1=Number(typeneede);
- let lastoxygen=100- AllAstrounafts[name].oxigen;
- if(lastoxygen <amount1){
- amount1=lastoxygen;
- }
- AllAstrounafts[name].oxigen +=amount1;
- if( AllAstrounafts[name].oxigen >100){
- AllAstrounafts[name].oxigen=100;
- }
- console.log(`${name} took a breath and recovered ${amount1} oxygen!`)
- break;
- }
- FirstLine= input.shift();
- }
- for (const astrounaft in AllAstrounafts) {
- console.log(`Astronaut: ${astrounaft}, Oxygen: ${AllAstrounafts[astrounaft].oxigen}, Energy: ${AllAstrounafts[astrounaft].energy}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement