Submission #39212

# Submission time Handle Problem Language Result Execution time Memory
39212 2018-01-10T07:14:14 Z qoo2p5 Toll (APIO13_toll) C++14
Compilation error
0 ms 0 KB
package ru.sirius.lambdas;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.function.Function;

public class LambdasExpressionTest {
    public static final String ALPHABET = "ABSCEFGIHJKLMNOPQRSTUVXWZ";
    private static final int MAX_WORD_LENGTH = 10;
    public static final Calendar CALENDAR = Calendar.getInstance();
    public static final SimpleDateFormat SDF = new SimpleDateFormat();

    static {
        SDF.applyPattern("MM/dd/yyyy");
    }

    public static void main(String[] args) {
        final List<Book> books = new ArrayList<>();
        final Random random = new Random();
        for (int i = 0; i < 1000; i++) {
            final Book book = Book.builder()
                    .author(generateString(random, ALPHABET, 2))
                    .code(generateString(random, ALPHABET, 1))
                    .receiverCode(random.nextInt())
                    .title(generateString(random, ALPHABET, Math.abs(1 + random.nextInt(4))))
                    .date(generateYearString(random))
                    .build();
            books.add(book);
        }

        books.stream()
                .filter(book -> Book.isOld(book) && book.getAuthor().startsWith("A"))
                .map(Book::getAuthor)
                .forEach(System.out::println);
    }

    interface CheckBook {
        boolean check(Book book) throws ParseException;
    }

    public static class CheckOldBookWithFamousAuthors implements CheckBook {

        @Override
        public boolean check(Book book) throws ParseException {
            CALENDAR.setTime(SDF.parse(book.getDate()));
            int year = CALENDAR.get(Calendar.YEAR);
            return year <= 1918 && book.getAuthor().startsWith("A");
        }
    }

    public static void printOldBooksWithFamousAuthors(List<Book> books, CheckBook checker) throws ParseException {
        for (Book book : books) {
            if (checker.check(book)) {
                System.out.println(String.valueOf(book));
            }
        }
    }

    //метод, который ищет, к примеру что-то по одной характеристике:
    public static void printBookOlderThen(List<Book> books,
                                          int year) throws ParseException {
        for (Book book : books) {
            CALENDAR.setTime(SDF.parse(book.getDate()));
            int bookYear = CALENDAR.get(Calendar.YEAR);
            if (bookYear < year) {
                System.out.println(book);
            }
        }
    }

    public static void printBookInRange(List<Book> books,
                                        int yearStart, int yearEnd) throws ParseException {
        for (Book book : books) {
            CALENDAR.setTime(SDF.parse(book.getDate()));
            int bookYear = CALENDAR.get(Calendar.YEAR);
            if (bookYear > yearStart && bookYear < yearEnd) {
                System.out.println(book);
            }
        }
    }


    private static String generateYearString(Random random) {
        int year = 1819 + Math.abs(random.nextInt(2018 - 1819));
        CALENDAR.set(Calendar.YEAR, year);
        int dayOfYear = 1 + Math.abs(random.nextInt(CALENDAR.getActualMaximum(Calendar.DAY_OF_YEAR)));
        CALENDAR.set(Calendar.DAY_OF_YEAR, dayOfYear);
        return SDF.format(CALENDAR.getTime());
    }

    private static String generateString(Random random, String alphabet, int words) {
        final StringBuilder builder = new StringBuilder();
        for (int i = 0; i < words; i++) {
            for (int j = 0; j < MAX_WORD_LENGTH; j++) {
                builder.append(alphabet.charAt(random.nextInt(alphabet.length())));
            }
            builder.append(" ");
        }
        return builder.toString();
    }
}

Compilation message

toll.cpp:47:9: error: stray '@' in program
         @Override
         ^
toll.cpp:1:1: error: 'package' does not name a type
 package ru.sirius.lambdas;
 ^
toll.cpp:3:1: error: 'import' does not name a type
 import java.text.ParseException;
 ^
toll.cpp:4:1: error: 'import' does not name a type
 import java.text.SimpleDateFormat;
 ^
toll.cpp:5:1: error: 'import' does not name a type
 import java.util.ArrayList;
 ^
toll.cpp:6:1: error: 'import' does not name a type
 import java.util.Calendar;
 ^
toll.cpp:7:1: error: 'import' does not name a type
 import java.util.List;
 ^
toll.cpp:8:1: error: 'import' does not name a type
 import java.util.Random;
 ^
toll.cpp:9:1: error: 'import' does not name a type
 import java.util.function.Function;
 ^
toll.cpp:11:1: error: expected unqualified-id before 'public'
 public class LambdasExpressionTest {
 ^