Sock Merchant

Run Settings
LanguageJava
Language Version
Run Command
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); } }
Editor Settings
Theme
Key bindings
Full width
Lines