Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package wenjalan;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Problem1 {
- final static String inputFile = "input1.txt";
- final static String outputFile = "output1.txt";
- // library data struct
- public static class Library {
- int id;
- int numberOfBooks;
- int signUpDays;
- int booksPerDay;
- List<Integer> books = new ArrayList<>();
- @Override
- public String toString() {
- return "\nLibrary{" +
- "\n\tid=" + id +
- ", \n\tnumberOfBooks=" + numberOfBooks +
- ", \n\tsignUpDays=" + signUpDays +
- ", \n\tbooksPerDay=" + booksPerDay +
- ", \n\tbooks=" + books +
- "}";
- }
- }
- // main
- public static void main(String[] args) {
- InputReader input = new InputReader(inputFile);
- OutputWriter output = new OutputWriter(outputFile);
- final int numberOfBooks = input.nextInt(); // B
- final int numberOfLibraries = input.nextInt(); // L
- final int numberOfDays = input.nextInt(); // D
- final int[] bookScores = new int[numberOfBooks];
- for (int i = 0; i < numberOfBooks; i++) {
- bookScores[i] = input.nextInt();
- }
- List<Library> libraries = new ArrayList<>();
- for (int i = 0; i < numberOfLibraries; i++) {
- Library library = new Library();
- library.id = i;
- library.numberOfBooks = input.nextInt();
- library.signUpDays = input.nextInt();
- library.booksPerDay = input.nextInt();
- for (int j = 0; j < library.numberOfBooks; j++) {
- library.books.add(input.nextInt());
- }
- libraries.add(library);
- }
- System.out.println(libraries);
- }
- // input reader helper class
- public static class InputReader {
- private Scanner scanner;
- public InputReader(String filepath) {
- try {
- this.scanner = new Scanner(new File(filepath));
- } catch (IOException e) {
- System.err.println("error reading input file");
- e.printStackTrace();;
- }
- }
- public String next() {
- return scanner.next();
- }
- public int nextInt() {
- return scanner.nextInt();
- }
- public String nextLine() {
- return scanner.nextLine();
- }
- public Scanner scanner() {
- return this.scanner;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement