06. Basketball Tournament Programming Basics Online Exam - 9 and 10 March 2019
Привет,
някой може ли да ми отвори очите защо получавам безкраен loop при този код за решението на тази задача :)
https://judge.softuni.bg/Contests/Practice/Index/1538#11
function basketBallTournament(input) {
let tournamentsName = input.shift();
let pointsCounterForDesi = 0;
let pointsCounterOtherTeam = 0;
let gamesCounter = 0;
let gamesWon = 0;
let gamesLost = 0;
let gamesPlayed = 0;
while(tournamentsName !== "End of tournaments") {
gamesPlayed = Number(input.shift());
for(let i = 0; i < gamesPlayed; i++) {
let pointsForDesi = Number(input.shift());
let pointsForOtherTeam = Number(input.shift());
gamesCounter++;
if(pointsForDesi > pointsForOtherTeam) {
gamesWon++;
console.log(`Game ${gamesCounter} of tournament ${tournamentsName}: win with ${pointsForDesi - pointsForOtherTeam} points.`);
} else if(pointsForDesi < pointsForOtherTeam) {
gamesLost++;
console.log(`Game ${gamesCounter} of tournament ${tournamentsName}: lost with ${pointsForOtherTeam - pointsForDesi} points.`);
}
} // for
} // while
let matchesWinPercent = (gamesWon / gamesPlayed) * 100;
let matchesLostPercent = (gamesLost / gamesPlayed) * 100;
if(tournamentsName === "End of tournaments") {
console.log(`Game ${matchesWinPercent}% matches win.`);
console.log(`Game ${matchesLostPercent}% matches lost.`);
}
}
basketBallTournament(["Dunkers", 2, 75, 65, 56, 73, "Fire Girls", 3, 67, 34, 83, 98, 66, 45, "End of tournaments"]);