Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. class Book{
  7.     int bookId;
  8.     int score;
  9.     public Book(int bookId,int score){
  10.         this.bookId=bookId;
  11.         this.score=score;
  12.     }
  13. }
  14. class Library{
  15.     int libraryId;
  16.     int numberOfBooks;
  17.     int timeToSignup;
  18.     int booksToShipPerDay;
  19.     List<Integer> booksIds;
  20.  
  21.     public Library(int libraryId, int numberOfBooks, int timeToSignup, int booksToShipPerDay, ArrayList<Integer>booksIds) {
  22.         this.numberOfBooks = numberOfBooks;
  23.         this.timeToSignup = timeToSignup;
  24.         this.booksToShipPerDay = booksToShipPerDay;
  25.         booksIds=new ArrayList<>();
  26.         this.booksIds=booksIds;
  27.     }
  28.    
  29.     public ArrayList<Book> getChosenOrderedBooks(){
  30.        
  31.     }
  32.  
  33.  
  34. }
  35. public class Array{
  36.  
  37.     public static ArrayList<Library> getChosenSortedLibraries(){
  38.  
  39.     }
  40.  
  41.     public static void solveTask(int numberOfBooks, ArrayList<Book> books, int numberOfLibraries,
  42.                                  ArrayList<Library> libraries, int numberOfDays) throws FileNotFoundException {
  43.  
  44.  
  45.         PrintWriter printWriter = new PrintWriter("output.txt");
  46.         ArrayList<Library> chosenLibraries = getChosenSortedLibraries();
  47.         int numberOfChosenLibraries = chosenLibraries.size();
  48.         printWriter.write(numberOfLibraries);
  49.         printWriter.write("\n");
  50.  
  51.         for (int i = 0; i < numberOfChosenLibraries ; i++) {
  52.             Library chosenLibrary = chosenLibraries.get(i);
  53.             printWriter.write(chosenLibrary.libraryId);
  54.             printWriter.write(" ");
  55.             ArrayList<Book> chosenBooksFromLibrary = chosenLibrary.getChosenOrderedBooks();
  56.             int numBooks = chosenBooksFromLibrary.size();
  57.             printWriter.write(numBooks);
  58.             printWriter.write("\n");
  59.             for (int j = 0; j < numBooks; j++) {
  60.                 Book chosenBook = chosenBooksFromLibrary.get(j);
  61.                 printWriter.write(chosenBook.bookId);
  62.                 printWriter.write(" ");
  63.             }
  64.             printWriter.write("\n");
  65.         }
  66.        
  67.         printWriter.flush();
  68.     }
  69.     public static void main(String[] args) throws IOException {
  70.         String fileName = "";
  71.         Scanner scanner = new Scanner(new FileReader(fileName));
  72.         int numberOfBooks = scanner.nextInt();
  73.         int numberOfLibraries = scanner.nextInt();
  74.         int numberOfDays = scanner.nextInt();
  75.         ArrayList<Book> books = new ArrayList<>();
  76.         for (int i = 0; i < numberOfBooks; i++) {
  77.             int bookScore = scanner.nextInt();
  78.             Book book = new Book(i,bookScore);
  79.             books.add(book);
  80.         }
  81.         ArrayList<Library> libraries = new ArrayList<>();
  82.         for (int i = 0; i < numberOfLibraries; i++) {
  83.             int numBooksInLibrary = scanner.nextInt();
  84.             int numDaysToSignup = scanner.nextInt();
  85.             int numBooksCanShip = scanner.nextInt();
  86.             ArrayList<Integer> booksIds = new ArrayList<>();
  87.             for (int j = 0; j < numBooksInLibrary; j++) {
  88.                 booksIds.add(scanner.nextInt());
  89.             }
  90.             Library library = new Library(i,numBooksInLibrary,numDaysToSignup,numBooksCanShip,booksIds);
  91.             libraries.add(library);
  92.         }
  93.  
  94.         solveTask(numberOfBooks,books,numberOfLibraries,libraries,numberOfDays);
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement