Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import java.io.*;
- import java.util.*;
- class lab04
- {
- public static void licz(int ile, Domino[] dom)
- {
- int[] kropki = new int[7];
- for (int i=0; i<ile; i++)
- {
- kropki[dom[i].getLeft()]++;
- kropki[dom[i].getRight()]++;
- }
- int licz_niep=0;
- int niep1=-1;
- int niep2=-1;
- for (int i=0; i<7; i++)
- {
- licz_niep+=kropki[i]%2;
- if (kropki[i]%2==1)
- if (niep1==-1) niep1=i;
- else niep2=i;
- // System.out.println("Kropek "+i+" jest: "+kropki[i]);
- }
- //System.out.println("Liczb nieparzystych jest: "+licz_niep);
- if (licz_niep==2)
- if (czy_istnieje(dom, niep1, niep2, ile))
- System.out.println("NIE");
- else
- {
- System.out.println(niep1+" "+niep2);
- }
- else
- System.out.println("NIE");
- }
- ////////////////////////////////////////////////////////////////////////////
- public static boolean czy_istnieje(Domino[] dom, int n1, int n2, int size)
- {
- for(int i=0; i<size; i++)
- {
- if ((dom[i].getLeft()==n1) && (dom[i].getRight()==n2) ) return true;
- if (dom[i].getLeft()==n2 && dom[i].getRight()==n1) return true;
- }
- return false;
- }
- ////////////////////////////////////////////////////////////////////////////
- public static void main (String[] args)
- {
- System.out.println("Wejście:");
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- Domino[] d= new Domino[n];
- for(int i=0; i<n; i++)
- {
- int x = in.nextInt();
- int y = in.nextInt();
- d[i]=new Domino (x,y);
- }
- //int y = in.nextInt();
- //System.out.println(x+"+"+y+"="+(x+y));
- /*int n=5;
- Domino[] d= new Domino[n];
- d[0]=new Domino (1,2);
- d[1]=new Domino (2,3);
- d[2]=new Domino (5,4);
- d[3]=new Domino (3,6);
- d[4]=new Domino (6,4);*/
- //for (int i=0; i<n; i++)
- // d[i].print();
- System.out.println();
- System.out.println("Wynik:");
- if (n==1) System.out.println(d[0].getLeft()+" "+d[0].getRight());
- else licz(n, d);
- }
- //////////////////////////////////////////////////////////////
- public static class Domino
- {
- private int _left;
- private int _right;
- public Domino(int left, int right)
- {
- _left=left;
- _right=right;
- }
- int getLeft(){ return _left;}
- int getRight(){ return _right;}
- void print()
- {
- System.out.print("("+getLeft()+" "+getRight()+")");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement