Rezultati

Up. imeNalogaJezikRezultatČas oddaje
bitikubiti-2017 Prijateljske besede Java 0/100Napačen odgovor (WA) 20. apr '17 @ 19:41

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 37,285 MiB 0,000 s OK
#2 0/12 41,766 MiB 0,000 s Napačen odgovor
Tvoj izhod:
​75
<<<EOF>>>
Pravilen izhod:
​76
<<<EOF>>>
#3 0/12 113,262 MiB 0,674 s Napačen odgovor
Tvoj izhod:
​2917
<<<EOF>>>
Pravilen izhod:
​2978
<<<EOF>>>
#4 0/12 120,016 MiB 1,009 s Napačen odgovor
Tvoj izhod:
​2133
<<<EOF>>>
Pravilen izhod:
​2154
<<<EOF>>>
#5 13/13 60,398 MiB 0,000 s OK
#6 0/13 120,758 MiB 0,798 s Napačen odgovor
Tvoj izhod:
​817
<<<EOF>>>
Pravilen izhod:
​819
<<<EOF>>>
#7 13/13 41,949 MiB 0,000 s OK
#8 13/13 111,414 MiB 0,771 s OK

Ocenjevani program (E.java):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by bitikubiti-2017 on 4/20/17.
 */
public class E {

    /*private static HashMap<String, List<String>> start1 = new HashMap<>();
    static HashMap<String, List<String>> end1 = new HashMap<>();
    static HashMap<String, List<String>> start2 = new HashMap<>();
    static HashMap<String, List<String>> end2 = new HashMap<>();

    static int res =0;

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String line, sub1, sub2;
        line = br.readLine();
        sub1 = line.substring(0, 3);
        sub2 = line.substring(line.length()-3);
        List<String> list = new ArrayList<>();
        list.add(line);
        start1.put(sub1, list);
        list = new ArrayList<>();
        list.add(line);
        end1.put(sub2, list);
        for(int i=1;i<n;i++) {
            line = br.readLine();
            testString(line);
        }
        System.out.println(res+1);
    }

    private static void testString (String line) {
        String sub1 = line.substring(0, 3);
        String sub2 = line.substring(line.length()-3);
        if(start1.containsKey(sub1) || end1.containsKey(sub2)) {
            if(start2.containsKey(sub1)) {
                List<String> list = start2.get(sub1);
                for(String s : list) {
                    start2.remove(sub1);
                    end2.remove(sub2);
                    testString (s);
                    putInMaps(s, start1, end1);
                }
            }
            if(end2.containsKey(sub2)) {
                List<String> list = end2.get(sub2);
                for(String s : list) {
                    start2.remove(sub1);
                    end2.remove(sub2);
                    testString (s);
                    putInMaps(s, start1, end1);
                }
            }
            putInMaps(line, start1, end1);
        }
        else {
            putInMaps(line, start2, end2);
        }
    }

    private static void putInMaps(String line, HashMap<String, List<String>> map1, HashMap<String, List<String>> map2) {
        res++;
        String sub1 = line.substring(0, 3);
        String sub2 = line.substring(line.length()-3);
        if(map1.containsKey(sub1) && map2.containsKey(sub2)) {
            map1.get(sub1).add(line);
            map2.get(sub2).add(line);
            return;
        }
        List list = new ArrayList<>();
        list.add(line);
        if(map1.containsKey(sub1)) {
            map1.get(sub1).add(line);
            map2.put(sub2, list);
            return;
        }
        if(map2.containsKey(sub2)) {
            map2.get(sub2).add(line);
            map1.put(sub1, list);
            return;
        }
        map1.put(sub1, list);
        list = new ArrayList<>();
        list.add(line);
        map2.put(sub2, list);
    }*/
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<String> tocheck = new ArrayList<>();
        tocheck.add(br.readLine());
        ArrayList<String> left = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            left.add(br.readLine());
        }
        int count = 1;
        ArrayList<String> checked = new ArrayList<>();
        boolean cont = true;
        while(cont){
            boolean check = false;
            for (int i = 0; i < tocheck.size(); i++) {
                String peek = tocheck.get(i);
                String[] leftt = new String[left.size()];
                for (int j = 0; j < leftt.length; j++) {
                    leftt[j] = left.get(j);
                }
                for(String b:leftt){
                    if(peek.substring(peek.length()-3).equals(b.substring(b.length()-3))||
                            peek.substring(0, 3).equals(b.substring(0, 3))){
                        if(!checked.contains(b)) {
                            checked.add(b);
                            left.remove(b);
                            tocheck.add(b);
                            count++;
                            check = true;
                        }
                    }
                }
            }
            if(!check)cont=false;

        }
        System.out.println(count);
    }
}