Advertisement
Vladkoheca

Svetovna ranglista po tenis.java

Mar 11th, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         // Четене на входните данни
  8.         int numTournaments = Integer.parseInt(scanner.nextLine());
  9.         int startingPoints = Integer.parseInt(scanner.nextLine());
  10.  
  11.         // Инициализация на променливи
  12.         int finalPoints = startingPoints;
  13.         int wonTournaments = 0;
  14.  
  15.         // Обхождане на всички турнири
  16.         for (int i = 0; i < numTournaments; i++) {
  17.             String tournamentResult = scanner.nextLine();
  18.  
  19.             if (tournamentResult.equals("W")) {
  20.                 finalPoints += 2000;
  21.                 wonTournaments++;
  22.             } else if (tournamentResult.equals("F")) {
  23.                 finalPoints += 1200;
  24.             } else if (tournamentResult.equals("SF")) {
  25.                 finalPoints += 720;
  26.             }
  27.         }
  28.  
  29.         // Изчисляване на средните точки и процента на спечелени турнири
  30.         int totalPoints = finalPoints - startingPoints;
  31.         int averagePoints = totalPoints / numTournaments;
  32.         double percentageWon = (double) wonTournaments / numTournaments * 100;
  33.  
  34.         // Извеждане на резултатите
  35.         System.out.println("Final points: " + finalPoints);
  36.         System.out.println("Average points: " + averagePoints);
  37.         System.out.printf("%.2f%%\n", percentageWon);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement