Quick actions

cmd+k|ctrl+k

Navigation

Languages

Sock Merchant

Snippet info

Language

Java

Visibility

public

Author

waricoma

Created

2020-02-02T10:31:17Z

Updated

2020-02-02T10:31:17Z

import java.util.Scanner;
import static java.lang.System.*;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(in);
    int n = scan.nextInt();
    ArrayList<Integer> cs = new ArrayList<>();
    for (int i = 0; i < n; ++i) {
      int c = scan.nextInt();
      cs.add(c);
    }
    ArrayList<Integer> fs = new ArrayList<>();
    int r = 0;
    for (int i = 0; i < n; ++i) {
      if (fs.indexOf(cs.get(i)) >= 0) {
        continue;
      }
      int g = 0;
      for (int j = 0; j < n; ++j) {
        if (cs.get(i) == cs.get(j)) ++g;
      }
      r += g / 2;
      fs.add(cs.get(i));
    }
    out.println(r);
  }
}
INFO