package com.sarojaba.algospot.newbie;
import java.io.File;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class A {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(new File("a.txt"));
int N = scanner.nextInt();
String[] lines = new String[N];
for (int i = 0; i < N; i++) {
lines[i] = scanner.nextLine();
}
System.out.println(solve(lines));
scanner.close();
}
public static int solve(String[] lines) {
Set mp3s = new HashSet<>();
Pattern pattern = Pattern.compile("(?:/.*)*/(.*)");
for (String l : lines) {
Matcher matcher = pattern.matcher(l);
String f = l;
if (matcher.matches()) {
f = matcher.group(1);
}
mp3s.add(MP3.parse(f));
}
return mp3s.size();
}
}
class MP3 {
private String artist;
private String song;
private int track;
public MP3(String artist, String song) {
this(artist, song, 0);
}
public MP3(String artist, String song, int track) {
this.artist = artist;
this.song = song;
this.track = track;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MP3)) {
return false;
}
MP3 mp3 = (MP3) obj;
if (!artist.equalsIgnoreCase(mp3.artist)) {
return false;
}
if (!song.equalsIgnoreCase(mp3.song)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return (artist.toLowerCase().hashCode() + song.toLowerCase().hashCode())
% Integer.MAX_VALUE;
}
@Override
public String toString() {
return String.format("{artist: %s, song: %s}", artist, song);
}
public static MP3 parse(String file) {
Pattern[] patterns = new Pattern[2];
patterns[0] = Pattern.compile("(.*)_(.*)_(.*)\\.mp3");
patterns[1] = Pattern.compile("(.*)\\. (.*) - (.*)\\.mp3");
for (Pattern p : patterns) {
Matcher matcher = p.matcher(file);
if (matcher.matches()) {
try {
int track = Integer.parseInt(matcher.group(1));
String artist = matcher.group(2);
String song = matcher.group(3);
return new MP3(artist, song, track);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
patterns[0] = Pattern.compile("(.*) - (.*)\\.mp3");
patterns[1] = Pattern.compile("(.*)_(.*)\\.mp3");
for (Pattern p : patterns) {
Matcher matcher = p.matcher(file);
if (matcher.matches()) {
String artist = matcher.group(1);
String song = matcher.group(2);
return new MP3(artist, song);
}
}
return null;
}
}