A - Games
Problem Link: [Codeforces 268A##link##]
- [tab]
- C++
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll n; cin>>n; ll a[n],b[n]; for(ll i=0;i<n;i++) { cin>>a[i]>>b[i]; } ll cnt=0; for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) { if(a[i]==b[j]) cnt++; } } cout<<cnt<<endl; }
- Python3
n=int(input()) w=0 list1=[] list2=[] for i in range(n): a,b=map(lambda x:int(x),input().split()) list1.append(a) list2.append(b) for i in list1: k=0 while k<len(list2): if i == list2[k]: w+=1 k+=1 print(w)
- JAVA
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Games { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()), result = 0; int[] home = new int[n]; int[] guest = new int[n]; for(int i = 0; i < n; i++) { home[i] = in.nextInt(); guest[i] = in.nextInt(); } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(home[i] == guest[j]) result++; System.out.println(result); } }