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 2.68 KB | None | 0 0
  1. package wenjalan;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class Problem1 {
  10.  
  11.     final static String inputFile = "input1.txt";
  12.     final static String outputFile = "output1.txt";
  13.  
  14.     // library data struct
  15.     public static class Library {
  16.         int id;
  17.         int numberOfBooks;
  18.         int signUpDays;
  19.         int booksPerDay;
  20.         List<Integer> books = new ArrayList<>();
  21.  
  22.         @Override
  23.         public String toString() {
  24.             return "\nLibrary{" +
  25.                     "\n\tid=" + id +
  26.                     ", \n\tnumberOfBooks=" + numberOfBooks +
  27.                     ", \n\tsignUpDays=" + signUpDays +
  28.                     ", \n\tbooksPerDay=" + booksPerDay +
  29.                     ", \n\tbooks=" + books +
  30.                     "}";
  31.         }
  32.     }
  33.  
  34.     // main
  35.     public static void main(String[] args) {
  36.         InputReader input = new InputReader(inputFile);
  37.         OutputWriter output = new OutputWriter(outputFile);
  38.  
  39.         final int numberOfBooks = input.nextInt(); // B
  40.         final int numberOfLibraries = input.nextInt(); // L
  41.         final int numberOfDays = input.nextInt(); // D
  42.         final int[] bookScores = new int[numberOfBooks];
  43.         for (int i = 0; i < numberOfBooks; i++) {
  44.             bookScores[i] = input.nextInt();
  45.         }
  46.  
  47.         List<Library> libraries = new ArrayList<>();
  48.         for (int i = 0; i < numberOfLibraries; i++) {
  49.             Library library = new Library();
  50.             library.id = i;
  51.             library.numberOfBooks = input.nextInt();
  52.             library.signUpDays = input.nextInt();
  53.             library.booksPerDay = input.nextInt();
  54.             for (int j = 0; j < library.numberOfBooks; j++) {
  55.                 library.books.add(input.nextInt());
  56.             }
  57.             libraries.add(library);
  58.         }
  59.         System.out.println(libraries);
  60.     }
  61.  
  62.     // input reader helper class
  63.     public static class InputReader {
  64.  
  65.         private Scanner scanner;
  66.  
  67.         public InputReader(String filepath) {
  68.             try {
  69.                 this.scanner = new Scanner(new File(filepath));
  70.             } catch (IOException e) {
  71.                 System.err.println("error reading input file");
  72.                 e.printStackTrace();;
  73.             }
  74.         }
  75.  
  76.         public String next() {
  77.             return scanner.next();
  78.         }
  79.  
  80.         public int nextInt() {
  81.             return scanner.nextInt();
  82.         }
  83.  
  84.         public String nextLine() {
  85.             return scanner.nextLine();
  86.         }
  87.  
  88.         public Scanner scanner() {
  89.             return this.scanner;
  90.         }
  91.  
  92.     }
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement