Programming basic Java - Game of Intervals, Exam - 18 March 2017
Здравейте, някой има ли решение на задача Game of Intervals.
Здравейте, някой има ли решение на задача Game of Intervals.
Ето едно на C#, което може да си адаптираш на Java -> https://pastebin.com/2NBSW9qJ
Здравей,
Изпращам моето решение.
Поздрави
import java.util.Scanner; public class TestForumQuestionGameOfIntervals { public static void main(String[] args) { Scanner console = new Scanner(System.in); int moves = Integer.parseInt(console.nextLine()); double score = 0; int groupOne = 0; int groupTwo = 0; int groupThree = 0; int groupFour = 0; int groupFive = 0; int invalidNumbers = 0; int counter = 1; while(counter <= moves) { int number = Integer.parseInt(console.nextLine()); if (number >= 0 && number <= 9) { groupOne++; score += number * 0.20; } else if (number >= 10 && number <= 19) { groupTwo++; score += number * 0.30; } else if (number >= 20 && number <= 29) { groupThree++; score += number * 0.40; } else if (number >= 30 && number <= 39) { groupFour++; score += 50; } else if (number >= 40 && number <= 50) { groupFive++; score += 100; } else { invalidNumbers++; score = score / 2; } counter++; } double percentageGroupOne = (double)groupOne / moves * 100; double percentageGroupTwo = (double) groupTwo / moves * 100; double percentageGroupThree = (double) groupThree / moves * 100; double percentageGroupFour = (double) groupFour / moves * 100; double percentageGroupFive = (double) groupFive / moves * 100; double percentageInvalidNumbers = (double) invalidNumbers / moves * 100; System.out.printf("%.2f%n", score); System.out.printf("From 0 to 9: %.2f%%%n", percentageGroupOne); System.out.printf("From 10 to 19: %.2f%%%n", percentageGroupTwo); System.out.printf("From 20 to 29: %.2f%%%n", percentageGroupThree); System.out.printf("From 30 to 39: %.2f%%%n", percentageGroupFour); System.out.printf("From 40 to 50: %.2f%%%n", percentageGroupFive); System.out.printf("Invalid numbers: %.2f%%%n", percentageInvalidNumbers); } }
Супер. Мерси!