Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Asistentite na FINKI treba da se rasporedat kako testatori vo edna ispitna sesija po povekje predmeti. Za sekoj predmet se znae vo kolku prostorii se polaga, odnosno kolku asistenti zahteva. Problemot nastanal sto nekoi od asistentite zaminale na sluzbeno patuvanje i nema da mozat da prisustvuvaat na ispitnata sesija. Potrebno e da se napravi rasporeduvanje taka sto asistentite se selektiraat kako vo redica. Koga ke se raspredat site asistenti po ednas, pocnuva odnovo rasporeduvanjeto od prviot asistent itn.
- 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 Asistenti {
- public static void main(String[] args) {
- Scanner input= new Scanner(System.in);
- int numAssisstants= Integer.parseInt(input.nextLine());
- ArrayQueue<String> assisstants= new ArrayQueue<String>(numAssisstants);
- String[] asistenti= input.nextLine().split("\\s+");
- for(int i=0;i<numAssisstants;i++){
- assisstants.enqueue(asistenti[i]);
- }
- int numSubjects= Integer.parseInt(input.nextLine());
- String[] predmeti= new String[numSubjects];
- Integer[] br_asistenti= new Integer[numSubjects];
- for(int i=0;i<numSubjects;i++){
- String[] info= input.nextLine().split("\\s+");
- predmeti[i]= info[0];
- br_asistenti[i]= Integer.parseInt(info[1]);
- }
- int numMissing= Integer.parseInt(input.nextLine());
- numAssisstants-=numMissing;
- String[] missing_assistants= input.nextLine().split("\\s+");
- ArrayQueue<String> temp= new ArrayQueue<>(numAssisstants);
- while(!assisstants.isEmpty()){
- int flag=0;
- for(int i=0;i <numMissing;i++){
- if(assisstants.peek().equals(missing_assistants[i])){
- assisstants.dequeue();
- flag=1;
- break;
- }
- }
- if(flag==1) continue;
- temp.enqueue(assisstants.dequeue());
- }
- while(!temp.isEmpty()) assisstants.enqueue(temp.dequeue());
- //while(!assisstants.isEmpty()) System.out.println(assisstants.dequeue());
- for(int i=0;i<numAssisstants;i++){
- System.out.println(predmeti[i]);
- System.out.println(br_asistenti[i]);
- for(int j=0;j<br_asistenti[i];j++){
- System.out.println(assisstants.peek());
- assisstants.enqueue(assisstants.dequeue());
- }
- }
- }
- }
- /*
- Sample input
- 4
- IlinkaIvanoska IgorKulev MagdalenaKostoska HristinaMihajloska
- 3
- APS 3
- MIS 1
- OOS 2
- 1
- HristinaMihajloska
- Sample output
- APS
- 3
- IlinkaIvanoska
- IgorKulev
- MagdalenaKostoska
- MIS
- 1
- IlinkaIvanoska
- OOS
- 2
- IgorKulev
- MagdalenaKostoska
- Sample input
- 6
- IlinkaIvanoska DzoceSrce OmniScient IgorKulev MagdalenaKostoska HristinaMihajloska
- 4
- APS 4
- NP 1
- SP 4
- KMIB 3
- 2
- HristinaMihajloska IlinkaIvanoska
- Sample output
- APS
- 4
- DzoceSrce
- OmniScient
- IgorKulev
- MagdalenaKostoska
- NP
- 1
- DzoceSrce
- SP
- 4
- OmniScient
- IgorKulev
- MagdalenaKostoska
- DzoceSrce
- KMIB
- 3
- OmniScient
- IgorKulev
- MagdalenaKostoska
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement