A. Games

A. Games

import java.util.Scanner;

public class Games {
	private static class Team {

		public Team(int home, int guest) {
			this.home = home;
			this.guest = guest;
		}

		int home;
		int guest;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		Team[] teams = new Team[n];

		for (int i = 0; i < n; i++) {
			teams[i] = new Team(in.nextInt(), in.nextInt());
		}

		int guestUniformGames = 0;

		for (int i = 0; i < teams.length; i++)
			for (int j = 0; j < teams.length; j++)
				if (i != j)
					if (teams[i].home == teams[j].guest)
						guestUniformGames++;

		System.out.println(guestUniformGames);
	}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s