Rezultati

Up. imeNalogaJezikRezultatČas oddaje
GrekikiSquad-2017 Prijateljske besede Java 100/100OK 20. apr '17 @ 18:05

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 37,695 MiB 0,000 s OK
#2 12/12 40,590 MiB 0,000 s OK
#3 12/12 61,406 MiB 1,149 s OK
#4 12/12 57,113 MiB 0,957 s OK
#5 13/13 52,090 MiB 0,780 s OK
#6 13/13 60,930 MiB 0,779 s OK
#7 13/13 60,949 MiB 0,591 s OK
#8 13/13 63,402 MiB 0,778 s OK

Ocenjevani program (naloga1.java):
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class naloga1 {
	public static boolean fr(String a,String b) {
		boolean left=true;
		boolean right=true;
		for(int i=0;i<3;i++) {
			if(a.charAt(i)!=b.charAt(i)) {
				left=false;
			}
			if(a.charAt(a.length()-1-i)!=b.charAt(b.length()-1-i)) {
				right=false;
			}
		}
		return left||right;
	}
	public static void print(boolean[]q) {
		for(int i=0;i<q.length;i++) {
			System.out.println(q[i]?"1":"0");
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int a=Integer.parseInt(in.nextLine());
		String[]q=new String[a];
		for(int i=0;i<a;i++) {
			q[i]=in.nextLine();
		}
		boolean[]ok=new boolean[a];
		boolean[]novo=new boolean[a];
		novo[0]=true;
		boolean[][]check=new boolean[a][a];
		for(int i=0;i<a;i++) {
			for(int j=0;j<a;j++) {
				check[i][j]=fr(q[i],q[j]);
			}
		}
		Queue<Integer>bs=new LinkedList<Integer>();
		ok[0]=true;
		bs.add(0);
		while(bs.size()>0) {
			int t=bs.poll();
			ok[t]=true;
			for(int i=0;i<a;i++) {
				if(fr(q[t],q[i])) {
					if(!ok[i]) {
						bs.add(i);
						ok[i]=true;
					}
				}
			}
		}
		//print(ok);
		int t=0;
		for(int i=0;i<a;i++) {
			if(ok[i]) {
				t++;
			}
		}
		System.out.println(t);
	}
}