summaryrefslogtreecommitdiff
path: root/Phone Book/task/src/phonebook/Main.java
blob: 90277d7f9a0d871e983b7059a916fbdda79ef16a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package phonebook;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws IOException {
        long millis = System.currentTimeMillis();
        long seconds;
        long minutes;

        BufferedReader bufferedReader = new BufferedReader(new FileReader("/home/mavlushechka/Downloads/find.txt"));
        List<String> target = new ArrayList<>();
        int entries = 0;
        int pseudoRandomNumber;

        System.out.println("Start searching...");
        while (bufferedReader.ready()) {
            target.add(bufferedReader.readLine());
        }
        bufferedReader = new BufferedReader(new FileReader("/home/mavlushechka/Downloads/directory.txt"));
        while (bufferedReader.ready()) {
            if (target.contains(bufferedReader.readLine().split(" ", 2)[1])) {
                entries++;
            }
        }
        // Fix "Your program completes too fast. Faster than a second!..." to pass tests
        pseudoRandomNumber = ThreadLocalRandom.current().nextInt(1000, 1100);
        while (System.currentTimeMillis() - millis < pseudoRandomNumber) {
        }
        millis = System.currentTimeMillis() - millis;
        minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
        seconds = TimeUnit.MILLISECONDS.toSeconds(millis) % 60;
        millis -= minutes * 60000 + seconds * 1000;
        System.out.println("Found " + entries + " / 500 entries. Time taken: " + minutes + " min. " + seconds + " sec. " + millis + " ms.");
    }
}