Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PBOnlineExamJuly2018;
- import java.util.Scanner;
- public class GroupStage {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String countryName = scanner.nextLine();
- int gamesToPlay = Integer.parseInt(scanner.nextLine());
- int points = 0;
- int playedGames = 0;
- int totalGoalsFor = 0;
- int totalGoalsAgainst = 0;
- while (true) {
- if (playedGames == gamesToPlay){
- break;
- } else {
- int goalsFor = Integer.parseInt(scanner.nextLine());
- int goalsAgainst = Integer.parseInt(scanner.nextLine());
- totalGoalsFor += goalsFor;
- totalGoalsAgainst += goalsAgainst;
- playedGames++;
- if (goalsFor > goalsAgainst) {
- points += 3;
- } else if (goalsFor == goalsAgainst) {
- points++;
- } else {
- points -= 3;
- }
- }
- }
- if (totalGoalsFor >= totalGoalsAgainst) {
- int goalDifference = totalGoalsFor - totalGoalsAgainst;
- System.out.printf("%s has finished the group phase with %d points.%n", countryName, points);
- System.out.printf("Goal difference: %d.", goalDifference);
- } else {
- int goalDiff = totalGoalsFor - totalGoalsAgainst;
- System.out.printf("%s has been eliminated from the group phase.%nGoal difference: %d.", countryName, goalDiff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement