Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kolokviumska od krajot na 2010s, me izmori fino i poshteno.
- // Studenti se prijavuvaat na anketa da polagaat APS vo bilo koj termin ili vo prviot termin dokolku polagaat istiot den nesto drugo. Arno ama asistentite dobivaat lista od studentite koi izlazale deka polagaat nesto drugo na anketata i tie se stavaat na krajot anketata polaganje vo bilo koj termin. Razgledaj input i output... Vo dvata termini polagaat n broj na studenti!
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.NoSuchElementException;
- import java.util.Queue;
- import java.util.Scanner;
- import java.util.*;
- import java.io.*;
- class ArrayQueue<E> implements Queue<E> {
- // Redicata e pretstavena na sledniot nacin:
- // length go sodrzi brojot na elementi.
- // Ako length > 0, togash elementite na redicata se zachuvani vo elems[front...rear-1]
- // Ako rear > front, togash vo elems[front...maxlength-1] i elems[0...rear-1]
- E[] elems;
- int length, front, rear;
- // Konstruktor ...
- @SuppressWarnings("unchecked")
- public ArrayQueue (int maxlength) {
- elems = (E[]) new Object[maxlength];
- clear();
- }
- public boolean isEmpty () {
- // Vrakja true ako i samo ako redicata e prazena.
- return (length == 0);
- }
- public int size () {
- // Ja vrakja dolzinata na redicata.
- return length;
- }
- public E peek () {
- // Go vrakja elementot na vrvot t.e. pocetokot od redicata.
- if (length > 0)
- return elems[front];
- else
- throw new NoSuchElementException();
- }
- public void clear () {
- // Ja prazni redicata.
- length = 0;
- front = rear = 0; // arbitrary
- }
- public void enqueue (E x) {
- // Go dodava x na kraj od redicata.
- elems[rear++] = x;
- if (rear == elems.length) rear = 0;
- length++;
- }
- public E dequeue () {
- // Go otstranuva i vrakja pochetniot element na redicata.
- if (length > 0) {
- E frontmost = elems[front];
- elems[front++] = null;
- if (front == elems.length) front = 0;
- length--;
- return frontmost;
- } else
- throw new NoSuchElementException();
- }
- @Override
- public boolean addAll(Collection<? extends E> arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean contains(Object arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean containsAll(Collection<?> arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public Iterator<E> iterator() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean remove(Object arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean removeAll(Collection<?> arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean retainAll(Collection<?> arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public Object[] toArray() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public <T> T[] toArray(T[] arg0) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean add(E arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public E element() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean offer(E arg0) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public E poll() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public E remove() {
- // TODO Auto-generated method stub
- return null;
- }
- }
- public class APSKolokvium {
- public static void main(String[] args) {
- Scanner input= new Scanner(System.in);
- int n= Integer.parseInt(input.nextLine());
- ArrayQueue<String> termin1= new ArrayQueue<String>(n);
- ArrayQueue<String> termin2= new ArrayQueue<String>(n);
- int numAnketa1= Integer.parseInt(input.nextLine());
- int numAnketa2= Integer.parseInt(input.nextLine());
- ArrayQueue<String> anketa1= new ArrayQueue<>(numAnketa1+numAnketa2);
- ArrayQueue<String> anketa2= new ArrayQueue<>(numAnketa2+numAnketa1);
- String[] studenti_anketa1= input.nextLine().split("\\s+");
- for(int i=0;i<numAnketa1;i++){
- anketa1.enqueue(studenti_anketa1[i]);
- }
- String[] studenti_anketa2= input.nextLine().split("\\s+");
- for(int i=0;i<numAnketa2;i++){
- anketa2.enqueue(studenti_anketa2[i]);
- }
- int numLazgovci= Integer.parseInt(input.nextLine());
- String[] lazgovci= input.nextLine().split("\\s+");
- int counter_termin1=0;
- while(!anketa1.isEmpty()){
- int flag=0;
- if(numLazgovci!=0){
- for(int i=0;i<lazgovci.length;i++){
- //System.out.println(anketa1.peek()+ " "+ lazgovci[i]);
- if(anketa1.peek().equals(lazgovci[i])){
- anketa2.enqueue(anketa1.dequeue());
- flag=1;
- break;
- }
- }
- }
- if(flag==1) continue;
- if(anketa1.isEmpty()) break;
- if(counter_termin1==n) break;
- termin1.enqueue(anketa1.dequeue());
- counter_termin1++;
- }
- while(!anketa1.isEmpty()){
- if(numLazgovci!=0){
- for(int i=0;i<lazgovci.length;i++){
- if(anketa1.peek().equals(lazgovci[i])) {
- anketa2.enqueue(anketa1.dequeue());
- continue;
- }
- }
- }
- if(counter_termin1==n)
- termin2.enqueue(anketa1.dequeue());
- else{
- termin1.enqueue(anketa1.dequeue());
- counter_termin1++;
- }
- }
- while(!anketa2.isEmpty()){
- if(counter_termin1==n){
- termin2.enqueue(anketa2.dequeue());
- }
- else{
- termin1.enqueue(anketa2.dequeue());
- counter_termin1++;
- }
- }
- System.out.print("TERMIN 1: ");
- while(!termin1.isEmpty()) System.out.print(termin1.dequeue()+" ");
- System.out.println();
- System.out.print("TERMIN 2: ");
- while(!termin2.isEmpty()) System.out.print(termin2.dequeue()+" ");
- }
- }
- /*
- 4
- 5
- 3
- Ana Maja Despina Angela Mirjana
- Nono Dzoce Marski
- 3
- Maja Despina Ana
- TERMIN 1: Angela Mirjana Nono Dzoce
- TERMIN 2: Marski Ana Maja Despina
- 4
- 7
- 1
- Ana Maja Despina Angela Mirjana Dzoce Marski
- Nono
- 2
- Despina Maja
- TERMIN 1: Ana Angela Mirjana Dzoce
- TERMIN 2: Marski Nono Maja Despina
- 4
- 1
- 7
- Nono
- Ana Maja Despina Angela Mirjana Dzoce Marski
- 1
- Nono
- TERMIN 1: Ana Maja Despina Angela
- TERMIN 2: Mirjana Dzoce Marski Nono
- 4
- 5
- 3
- Ana Maja Despina Angela Mirjana
- Nono Dzoce Marski
- 0
- Empty
- TERMIN 1: Ana Maja Despina Angela
- TERMIN 2: Mirjana Nono Dzoce Marski
- 5
- 2
- 6
- Nono Dzoce
- Ana Maja Despina Angela Mirjana Jana
- 0
- Empty
- TERMIN 1: Nono Dzoce Ana Maja Despina
- TERMIN 2: Angela Mirjana Jana
- 5
- 2
- 2
- Nono Dzoce
- Ana Maja
- 0
- Empty
- TERMIN 1: Nono Dzoce Ana Maja
- TERMIN 2:
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement