PTA题目集6-8

一、前言

这次题目集6-7的难度不算特别高,题目集8难度对于我个人来说略高,题量都属于中等偏下水平。涉及到的知识点与前面菜单题目集没有太大区别,都是类,接口等方面的知识。

二、设计与分析

大部分设计的比较一般,注释行较多,具有可读性,结构较为清晰

1.PTA-6

这次题目总分100,其实我只拿到了80,有测试点卡住,无法通过,下面这个是习题集结束后重新做的,可以拿到100

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
     static ArrayList<Student> students = new ArrayList<>();
     static ArrayList<Class> classes = new ArrayList<>();
     static ArrayList<Course> courses = new ArrayList<>();
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String string = input.nextLine();
        while (!string.equals("end")){
            analyse(string);
            string = input.nextLine();
        }
        //输出学生,课程,班级信息
        showMessage();
    }
    public static void analyse(String string){
        Match match = new Match();
        int flag = match.match(string);
        switch (flag){
            case 0:
                System.out.println("wrong format");
                break;
            case 1:
                courseMessage(string);
                break;
            case 2:
                scoreMessage(string);
                break;
        }
    }
    //添加课程信息
    public static void courseMessage(String string){
        String[] str = string.split(" ");
        String name = str[0];
        String nature = str[1];
        String method = str[2];
        //如果课程信息合理
        if(checkCourse(name,nature,method)){
            if (searchCourse(name) == null) {
                courses.add(new Course(name, nature, method));
            }
        }
    }
    //检查课程
    public static boolean checkCourse(String name,String nature, String method){
        if(nature.equals("必修") && method.equals("考试"))
            return true;
        if(nature.equals("选修")){
            return method.equals("考试") || method.equals("考察");
        }
        System.out.println(name+" : course type & access mode mismatch");
        return false;
    }
    //搜索课程
    public static Course searchCourse(String name){
        for (Course course:courses) {
            if(course.name.equals(name))
                return course;
        }
        return null;
    }
    //添加成绩信息
    public static void scoreMessage(String string){
        String[] str = string.split(" ");
        String ID = str[0];
        String number = ID.substring(0,6);
        String name = str[1];
        String courseName = str[2];

        Class cla;
        //如果该班级第一次出现
        if(searchClass(number) == null){
            cla = new Class(number);
            classes.add(cla);
        }
        //如果该班级存在
        else {
            cla = searchClass(number);
        }

        Student student;
        //如果该学生不存在
        if(searchStudent(ID)==null){
            student = new Student(ID,name);
            students.add(student);
            cla.addStudent(student);
        }
        //如果该学生存在
        student = searchStudent(ID);

        //如果课程不存在
        if(searchCourse(courseName)==null){
            System.out.println(courseName+" does not exist");
        }
        //如果课程存在
        else if(searchCourse(courseName)!=null){
            Course course = searchCourse(courseName);
            //考试
            if(course.method.equals("考试") && str.length == 5){
                int dailyScore = Integer.parseInt(str[3]);
                int finalScore = Integer.parseInt(str[4]);
                ExaminationScore score = new ExaminationScore(dailyScore,finalScore);
                Selection selection = new Selection(course,student,score);
                if(searchSelection(student,course)==null){
                    course.addSelection(selection);
                    student.addSelection(selection);
                }
            }
            //考察
            else if(course.method.equals("考察") && str.length == 4){
                int finalScore = Integer.parseInt(str[3]);
                AssessmentScore score = new AssessmentScore(finalScore);
                Selection selection = new Selection(course,student,score);
                if(searchSelection(student,course)==null){
                    course.addSelection(selection);
                    student.addSelection(selection);
                }
            }
            else{
                System.out.println(ID+" "+name+" : access mode mismatch");
            }
        }
    }
    public static Selection searchSelection(Student student,Course course){
        for (Selection selection: student.selections){
            if(selection.course.equals(course)){
                return selection;
            }
        }
        return null;
    }
    public static Class searchClass(String number){
        for (Class cla:classes) {
            if(cla.number.equals(number)){
                return cla;
            }
        }
        return null;
    }
    //搜索学生
    public static Student searchStudent(String ID){
        for (Student student:students) {
            if(student.ID.equals(ID))
                return student;
        }
        return null;
    }
    //输出学生,课程,班级信息
    public static void showMessage(){
        Collections.sort(students);
        for (Student stu:students) {
            stu.printStudent();
        }
        Collections.sort(courses);
        for (Course course:courses) {
            course.printCourse();
        }
        Collections.sort(classes);
        for (Class cla:classes) {
            cla.printClass();
        }
    }
}
/*班级*/
class Class implements Comparable<Class>{
    String number;
    ArrayList<Student> students = new ArrayList<>();
    public Class(String number) {
        this.number = number;
    }
    public void addStudent(Student student){
        this.students.add(student);
    }
    public int getAverageScore(){
        int sum = 0;
        for (Student stu:students){
            sum += stu.getAverageScore();
        }
        return sum /students.size();
    }
    public boolean scoreIsNull(){
        for (Student stu:students) {
            if(stu.selections.size()!=0){
                return false;
            }
        }
        return true;
    }
    //输出班级信息
    public void printClass(){
        if(scoreIsNull()){
            System.out.println(number+" has no grades yet");
        }
        else {
            System.out.println(number+" "+getAverageScore());
        }
    }
    //排列
    @Override
    public int compareTo(Class o) {
        return number.compareTo(o.number);
    }
}
/*学生*/
class Student implements Comparable<Student>{
    String ID;
    String name;
    ArrayList<Selection> selections = new ArrayList<>();
    public Student(String ID, String name) {
        this.ID = ID;
        this.name = name;
    }
    public void addSelection(Selection selection){
        this.selections.add(selection);
    }
    //输出学生信息
    public void printStudent(){
        if(selections.size() == 0){
            System.out.println(ID+" "+name+" did not take any exams");
        }
        else {
            System.out.println(ID+" "+name+" "+getAverageScore());
        }
    }
    //个人平均成绩
    public int getAverageScore(){
        int sum = 0;
        for (Selection s:selections) {
            sum += s.score.getScore();
        }
        return sum /selections.size();
    }
    //排列
    @Override
    public int compareTo(Student o) {
        return this.ID.compareTo(o.ID);
    }
}
/*选课*/
class Selection{
    Course course;
    Student student;
    Score score;
    public Selection(Course course, Student student, Score score) {
        this.course = course;
        this.student = student;
        this.score = score;
    }
}
/*课程*/
class Course implements Comparable<Course>{
    String name;
    String nature;
    String method;
    ArrayList<Selection> selections = new ArrayList<>();
    public Course(String name, String nature, String method) {
        this.name = name;
        this.nature = nature;
        this.method = method;
    }
    public void addSelection(Selection selection){
        this.selections.add(selection);
    }
    public int getAverageDailyScore(){
        int sum = 0;
        for (Selection s:selections) {
            sum += s.score.getDailyScore();
        }
        return sum /selections.size();
    }
    public int getAverageFinalScore(){
        int sum = 0;
        for (Selection s:selections) {
            sum += s.score.getFinalScore();
        }
        return sum /selections.size();
    }
    public int getAverageScore(){
        int sum = 0;
        for (Selection s:selections){
            sum += s.score.getScore();
        }
        return sum/selections.size();
    }
    public void printCourse(){
        if(selections.size() == 0){
            System.out.println(name+" has no grades yet");
        }
        else if(method.equals("考察")){
            System.out.println(name+" "+getAverageFinalScore()+" "+getAverageScore());
        }
        else if(method.equals("考试")){
            System.out.println(name+" "+getAverageDailyScore()+" "+getAverageFinalScore()+" "+getAverageScore());
        }
    }
    public int compareTo(Course o) {
        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);
        return compare.compare(name,o.name);
    }
}
/*成绩*/
class Score{
    public int getScore(){
        return 0;
    }
    public int getDailyScore() {
        return 0;
    }
    public int getFinalScore() {
        return 0;
    }

}
/*考察成绩*/
class AssessmentScore extends Score{
    int finalScore;
    public AssessmentScore(int finalScore) {
        this.finalScore = finalScore;
    }
    public int getFinalScore() {
        return finalScore;
    }
    public int getScore(){
        return finalScore;
    }
}
/*考核成绩*/
class ExaminationScore extends Score{
    int dailyScore;
    int finalScore;
    public ExaminationScore(int dailyScore, int finalScore) {
        this.dailyScore = dailyScore;
        this.finalScore = finalScore;
    }
    public int getDailyScore() {
        return dailyScore;
    }
    public int getFinalScore() {
        return finalScore;
    }
    public int getScore(){
        return (int) (0.3*dailyScore+0.7*finalScore);
    }
}
class Match{
    static String stuNumMatch = "[0-9]{8}";//8个0-9的数字
    static String stuNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
    static String scoreMatch = "([1-9]?[0-9]|100)";
    static String courseNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
    static String courseTypeMatch = "(选修|必修)";
    static String checkCourseTypeMatch = "(考试|考察)";
    //courseInput用于定义课程信息模式(正则表达式)
    static String courseInput = courseNameMatch + " " + courseTypeMatch + " " + checkCourseTypeMatch;
    //scoreInput用于定义成绩信息模式(正则表达式)
    static String scoreInput1 = stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch;         //考察
    static String scoreInput2=  stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch + " " + scoreMatch;         //考试
    public int match(String string){
        if (matchingCourse(string))
            return 1;
        if (matchingScore(string))
            return 2;
        return 0;
    }
    //课程信息
    private static boolean matchingCourse(String s) {
        return s.matches(courseInput);
    }
    //成绩信息
    private static boolean matchingScore(String s) {
        return s.matches(scoreInput1) || s.matches(scoreInput2);
    }
}
课程成绩统计程序-1

2.PTA-7

这次题目集除了课程成绩统计程序-2差4分外,其余均为满分

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        Scanner input = new Scanner(System.in);
        String string = input.nextLine();
        while (!string.equals("end")){
            String[] array = string.split(" ");
            Student student = new Student(array[1],array[2]);
            hashMap.put(array[0],student);
            string = input.nextLine();
        }
        string = input.next();
        Student student = (Student) hashMap.get(string);
        if(student != null){
            System.out.println(string+" "+student.name+" "+student.score);
        }
        else {
            System.out.println("The student "+string+" does not exist");
        }
    }
}
class Student{
    String name;
    String score;

    public Student(String name, String score) {
        this.name = name;
        this.score = score;
    }
}
容器-HashMap-检索
 1 import java.util.ArrayList;
 2 import java.util.Collections;
 3 import java.util.HashMap;
 4 import java.util.Scanner;
 5 
 6 class Main {
 7     public static void main(String[] args) {
 8         HashMap<Object, Object> hashMap = new HashMap<>();
 9         ArrayList<String> ID = new ArrayList<>();
10         Scanner input = new Scanner(System.in);
11         String string = input.nextLine();
12         while (!string.equals("end")){
13             String[] array = string.split(" ");
14             Student student = new Student(array[1],array[2]);
15             hashMap.put(array[0],student);
16             ID.add(array[0]);
17             string = input.nextLine();
18         }
19         Collections.sort(ID);
20         for (int i = ID.size()-1; i>=0; i--) {
21             Student student = (Student) hashMap.get(ID.get(i));
22             System.out.println(ID.get(i)+" "+student.name+" "+student.score);
23         }
24     }
25 }
26 class Student{
27     String name;
28     String score;
29 
30     public Student(String name, String score) {
31         this.name = name;
32         this.score = score;
33     }
34 }
容器-HashMap-排序
import java.text.Collator;
import java.util.*;

public class Main {
    static ArrayList<Student> students = new ArrayList<>();
    static ArrayList<Class> classes = new ArrayList<>();
    static ArrayList<Course> courses = new ArrayList<>();
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String string = input.nextLine();
        while (!string.equals("end")){
            analyse(string);
            string = input.nextLine();
        }
        //输出学生,课程,班级信息
        showMessage();
    }
    public static void analyse(String string){
        Match match = new Match();
        int flag = match.match(string);
        switch (flag){
            case 0:
                System.out.println("wrong format");
                break;
            case 1:
                courseMessage(string);
                break;
            case 2:
                scoreMessage(string);
                break;
        }
    }
    //添加课程信息
    public static void courseMessage(String string){
        String[] str = string.split(" ");
        String name = str[0];
        String nature = str[1];
        String method = str[2];
        //如果课程信息合理
        if(checkCourse(name,nature,method)){
            if (searchCourse(name) == null) {
                courses.add(new Course(name, nature, method));
            }
        }
    }
    //检查课程
    public static boolean checkCourse(String name,String nature, String method){
        if(nature.equals("必修") && method.equals("考试")) {
            return true;
        }
        else if(nature.equals("选修")){
            return method.equals("考试") || method.equals("考察");
        }
        else if(nature.equals("实验") && method.equals("实验")){
            return true;
        }
        System.out.println(name+" : course type & access mode mismatch");
        return false;
    }
    //搜索课程
    public static Course searchCourse(String name){
        for (Course course:courses) {
            if(course.name.equals(name))
                return course;
        }
        return null;
    }
    //添加成绩信息
    public static void scoreMessage(String string){
        String[] str = string.split(" ");
        String ID = str[0];
        String number = ID.substring(0,6);
        String name = str[1];
        String courseName = str[2];

        Class cla;
        //如果该班级第一次出现
        if(searchClass(number) == null){
            cla = new Class(number);
            classes.add(cla);
        }
        //如果该班级存在
        else {
            cla = searchClass(number);
        }

        Student student;
        //如果该学生不存在
        if(searchStudent(ID)==null){
            student = new Student(ID,name);
            students.add(student);
            if (cla != null) {
                cla.addStudent(student);
            }
        }
        //如果该学生存在
        student = searchStudent(ID);

        //如果课程不存在
        if(searchCourse(courseName)==null){
            System.out.println(courseName+" does not exist");
        }
        //如果课程存在
        else if(searchCourse(courseName)!=null){
            Course course = searchCourse(courseName);
            //考试
            if(Objects.requireNonNull(course).method.equals("考试") && str.length == 5){
                int dailyScore = Integer.parseInt(str[3]);
                int finalScore = Integer.parseInt(str[4]);
                ExaminationScore score = new ExaminationScore(dailyScore,finalScore);
                Selection selection = new Selection(course,student,score);
                if (student != null && searchSelection(student, course) == null) {
                    course.addSelection(selection);
                    student.addSelection(selection);
                }
            }
            //考察
             else if(course.method.equals("考察") && str.length == 4){
                int finalScore = Integer.parseInt(str[3]);
                AssessmentScore score = new AssessmentScore(finalScore);
                Selection selection = new Selection(course,student,score);
                if (student != null && searchSelection(student, course) == null) {
                    course.addSelection(selection);
                    student.addSelection(selection);
                }
            }
            //实验
             else if(course.method.equals("实验")){
                 int times = Integer.parseInt(str[3]);
                 if(str.length == 4 + times){
                     ExperimentScore score =new ExperimentScore();
                     Selection selection = new Selection(course,student,score);
                     for (int i=4; i<str.length; i++){
                         score.addGrade(str[i]);
                     }
                     if (student != null && searchSelection(student, course) == null) {
                         course.addSelection(selection);
                         student.addSelection(selection);
                     }
                 }
                 else{
                    System.out.println(ID + " " + name + " : access mode mismatch");
                }
            }
            else {
                System.out.println(ID + " " + name + " : access mode mismatch");
            }
        }
    }
    public static Selection searchSelection(Student student,Course course){
        for (Selection selection: student.selections){
            if(selection.course.equals(course)){
                return selection;
            }
        }
        return null;
    }
    public static Class searchClass(String number){
        for (Class cla:classes) {
            if(cla.number.equals(number)){
                return cla;
            }
        }
        return null;
    }
    //搜索学生
    public static Student searchStudent(String ID){
        for (Student student:students) {
            if(student.ID.equals(ID))
                return student;
        }
        return null;
    }
    //输出学生,课程,班级信息
    public static void showMessage(){
        Collections.sort(students);
        for (Student stu:students) {
            stu.printStudent();
        }
        Collections.sort(courses);
        for (Course course:courses) {
            course.printCourse();
        }
        Collections.sort(classes);
        for (Class cla:classes) {
            cla.printClass();
        }
    }
}
/*班级*/
class Class implements Comparable<Class>{
    String number;
    ArrayList<Student> students = new ArrayList<>();
    public Class(String number) {
        this.number = number;
    }
    public void addStudent(Student student){
        this.students.add(student);
    }
    public int getAverageScore(){
        int sum = 0;
        int n = students.size();
        for (Student stu:students){
            if(stu.selections.size() != 0){
                sum += stu.getAverageScore();
            }
            else {
                n--;
            }
        }
        return sum /n;
    }
    public boolean scoreIsNull(){
        for (Student stu:students) {
            if(stu.selections.size()!=0){
                return false;
            }
        }
        return true;
    }
    //输出班级信息
    public void printClass(){
        if(scoreIsNull()){
            System.out.println(number+" has no grades yet");
        }
        else {
            System.out.println(number+" "+getAverageScore());
        }
    }
    //排列
    @Override
    public int compareTo(Class o) {
        return number.compareTo(o.number);
    }
}
/*学生*/
class Student implements Comparable<Student>{
    String ID;
    String name;
    ArrayList<Selection> selections = new ArrayList<>();
    public Student(String ID, String name) {
        this.ID = ID;
        this.name = name;
    }
    public void addSelection(Selection selection){
        this.selections.add(selection);
    }
    //输出学生信息
    public void printStudent(){
        if(selections.size() == 0){
            System.out.println(ID+" "+name+" did not take any exams");
        }
        else {
            System.out.println(ID+" "+name+" "+getAverageScore());
        }
    }
    //个人平均成绩
    public int getAverageScore(){
        int sum = 0;
        for (Selection s : selections) {
            sum += s.score.getScore();
        }
        return sum / selections.size();
    }
    //排列
    @Override
    public int compareTo(Student o) {
        return this.ID.compareTo(o.ID);
    }
}
/*选课*/
class Selection{
    Course course;
    Student student;
    Score score;
    public Selection(Course course, Student student, Score score) {
        this.course = course;
        this.student = student;
        this.score = score;
    }
}
/*课程*/
class Course implements Comparable<Course>{
    String name;
    String nature;
    String method;
    ArrayList<Selection> selections = new ArrayList<>();
    public Course(String name, String nature, String method) {
        this.name = name;
        this.nature = nature;
        this.method = method;
    }
    public void addSelection(Selection selection){
        this.selections.add(selection);
    }
    public int getAverageDailyScore(){
        int sum = 0;
        for (Selection s:selections) {
            sum += s.score.getDailyScore();
        }
        return sum /selections.size();
    }
    public int getAverageFinalScore(){
        int sum = 0;
        for (Selection s:selections) {
            sum += s.score.getFinalScore();
        }
        return sum /selections.size();
    }
    public int getAverageScore(){
        int sum = 0;
        for (Selection s:selections){
            sum += s.score.getScore();
        }
        return sum/selections.size();
    }
    public void printCourse(){
        if(selections.size() == 0){
            System.out.println(name+" has no grades yet");
        }
        else if(method.equals("考察")){
            System.out.println(name+" "+getAverageFinalScore()+" "+getAverageScore());
        }
        else if(method.equals("考试")){
            System.out.println(name+" "+getAverageDailyScore()+" "+getAverageFinalScore()+" "+getAverageScore());
        }
        else if(method.equals("实验")){
            System.out.println(name+" "+getAverageScore());
        }
    }
    public int compareTo(Course o) {
        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);
        return compare.compare(name,o.name);
    }
}
/*成绩*/
class Score{
    public int getScore(){
        return 0;
    }
    public int getDailyScore() {
        return 0;
    }
    public int getFinalScore() {
        return 0;
    }

}
/*考察成绩*/
class AssessmentScore extends Score{
    int finalScore;
    public AssessmentScore(int finalScore) {
        this.finalScore = finalScore;
    }
    public int getFinalScore() {
        return finalScore;
    }
    public int getScore(){
        return finalScore;
    }
}
/*考试成绩*/
class ExaminationScore extends Score{
    int dailyScore;
    int finalScore;
    public ExaminationScore(int dailyScore, int finalScore) {
        this.dailyScore = dailyScore;
        this.finalScore = finalScore;
    }
    public int getDailyScore() {
        return dailyScore;
    }
    public int getFinalScore() {
        return finalScore;
    }
    public int getScore(){
        return (int) (0.3*dailyScore+0.7*finalScore);
    }
}
/*实验成绩*/
class ExperimentScore extends Score{
    ArrayList<Integer> grades = new ArrayList<>();
    public ExperimentScore() {
    }
    public void addGrade(String grade){
        this.grades.add(Integer.parseInt(grade));
    }
    public int getScore() {
        int sum = 0;
        for (int grade:grades) {
            sum += grade;
        }
        return sum /grades.size();
    }
}
class Match{
    static String stuNumMatch = "[0-9]{8}";//8个0-9的数字
    static String stuNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
    static String scoreMatch = "([1-9]?[0-9]|100)";
    static String courseNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
    static String courseTimesMatch = "[4-9]";//1个4-9的数字
    static String courseTypeMatch = "(选修|必修|实验)";
    static String checkCourseTypeMatch = "(考试|考察|实验)";
    //courseInput用于定义课程信息模式(正则表达式)
    static String courseInput = courseNameMatch + " " + courseTypeMatch + " " + checkCourseTypeMatch;
    //scoreInput用于定义成绩信息模式(正则表达式)
    static String scoreInput1 = stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch;         //考察
    static String scoreInput2 =  stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch + " " + scoreMatch;         //考试
    static String scoreInput3 = stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " +courseTimesMatch;           //实验
    public int match(String string){
        if (matchingCourse(string))
            return 1;
        if (matchingScore(string))
            return 2;
        return 0;
    }
    //课程信息
    private static boolean matchingCourse(String s) {
        return s.matches(courseInput);
    }
    //成绩信息
    private static boolean matchingScore(String s) {
        int flag = matchingExperimentScore(s);
        switch (flag){
            case 0:
                return true;
            case 1:
                return false;
            case 2:
        }
        return s.matches(scoreInput1) || s.matches(scoreInput2);
    }
    public static int matchingExperimentScore(String s){
        String[] str = s.split(" ");
        if(str.length > 5){
            String temp= str[0]+" "+str[1]+" "+str[2]+" "+str[3];
            if(temp.matches(scoreInput3)){
                for(int i=4; i<str.length; i++){
                    if(!str[i].matches(scoreMatch))
                        return 1;           //false
                }
                return 0;           //true
            }
        }
        return 2;           //continue
    }
}
课程成绩统计程序-2
 1 //动物发生模拟器.  请在下面的【】处添加代码。
 2 public class Main {
 3     public static void main(String[] args) {
 4         Cat cat = new Cat();
 5         Dog dog = new Dog();
 6         Goat goat = new Goat();
 7         speak(cat);
 8         speak(dog);
 9         speak(goat);
10     }
11 
12     private static void speak(Animal animal) {
13         System.out.println(animal.getAnimalClass()+"的叫声:"+animal.shout());
14     }
15 }
16 
17 //定义抽象类Animal
18 class Animal{
19     String type;
20     String shout;
21     public String getAnimalClass(){
22         return type;
23     }
24     public String shout(){
25         return shout;
26     }
27 }
28 //基于Animal类,定义猫类Cat,并重写两个抽象方法
29 class Cat extends Animal{
30     public String getAnimalClass(){
31         return "猫";
32     }
33     public String shout(){
34         return "喵喵";
35     }
36         }
37 //基于Animal类,定义狗类Dog,并重写两个抽象方法
38 class Dog extends Animal{
39     public String getAnimalClass(){
40         return "狗";
41     }
42     public String shout(){
43         return "汪汪";
44     }
45         }
46 //基于Animal类,定义山羊类Goat,并重写两个抽象方法
47 class Goat extends Animal{
48     public String getAnimalClass(){
49         return "山羊";
50     }
51     public String shout(){
52         return "咩咩";
53     }
54         }
动物发声模拟器(多态)

3.PTA-8

这次花再课程成绩统计程序-3上的时间不多,导致最后并没有得分,但还是把代码放上来了,请勿参考

 1 import java.util.ArrayList;
 2 import java.util.Collections;
 3 import java.util.Scanner;
 4 
 5 public class Main {
 6     public static void main(String[] args) {
 7         ArrayList<Student> students = new ArrayList<>();
 8         Scanner input = new Scanner(System.in);
 9         String line = input.nextLine();
10         while (!line.equals("end")){
11             String[] str= line.split(" ");
12             Student student = new Student(str[0],str[1],str[2],str[3]);
13             students.add(student);
14             line = input.nextLine();
15         }
16         Collections.sort(students);
17         for (Student stu:students) {
18             System.out.println(stu.ID+" "+stu.name+" "+stu.grades());
19         }
20     }
21 }
22 class Student implements Comparable<Student>{
23     String ID;
24     String name;
25     int math;
26     int physics;
27 
28     public Student(String ID, String name, String math, String physics) {
29         this.ID = ID;
30         this.name = name;
31         this.math = Integer.parseInt(math);
32         this.physics = Integer.parseInt(physics);
33     }
34     public int grades(){
35         return math+physics;
36     }
37     @Override
38     public int compareTo(Student o) {
39         return o.grades()-this.grades();
40     }
41 }
容器-ArrayList-排序
  1 import java.text.Collator;
  2 import java.util.*;
  3 
  4 public class Main {
  5     static ArrayList<Student> students = new ArrayList<>();
  6     static ArrayList<Class> classes = new ArrayList<>();
  7     static ArrayList<Course> courses = new ArrayList<>();
  8     public static void main(String[] args) {
  9         Scanner input = new Scanner(System.in);
 10         String string = input.nextLine();
 11         while (!string.equals("end")){
 12             analyse(string);
 13             string = input.nextLine();
 14         }
 15         //输出学生,课程,班级信息
 16         showMessage();
 17     }
 18     public static void analyse(String string){
 19         Match match = new Match();
 20         int flag = match.match(string);
 21         switch (flag){
 22             case 0:
 23                 System.out.println("wrong format");
 24                 break;
 25             case 1:
 26                 courseMessage(string);
 27                 break;
 28             case 2:
 29                 scoreMessage(string);
 30                 break;
 31             default:
 32                 break;
 33         }
 34     }
 35     //添加课程信息
 36     public static void courseMessage(String string){
 37         String[] str = string.split(" ");
 38         String name = str[0];
 39         String nature = str[1];
 40         String method = str[2];
 41         //如果课程信息合理
 42         if(checkCourse(name,nature,method)){
 43             if (searchCourse(name) == null) {
 44                 switch (method) {
 45                     case "考察":
 46                         courses.add(new Course(name, nature, method));
 47                         break;
 48                     case "考试": {
 49                         double[] weights = {Double.parseDouble(str[3]), Double.parseDouble(str[4])};
 50                         Course course = new Course(name, nature, method);
 51                         course.setWeights(2, weights);
 52                         courses.add(course);
 53                         break;
 54                     }
 55                     case "实验": {
 56                         int n = Integer.parseInt(str[3]);
 57                         double[] weights = new double[n];
 58                         for (int i = 4, j = 0; i < str.length; i++, j++) {
 59                             weights[j] = Double.parseDouble(str[i]);
 60                         }
 61                         Course course = new Course(name, nature, method);
 62                         course.setWeights(n, weights);
 63                         courses.add(course);
 64                         break;
 65                     }
 66                 }
 67             }
 68         }
 69     }
 70     //检查课程
 71     public static boolean checkCourse(String name,String nature, String method){
 72         if(nature.equals("必修") && method.equals("考试")) {
 73             return true;
 74         }
 75         else if(nature.equals("选修")){
 76             return method.equals("考试") || method.equals("考察");
 77         }
 78         else if(nature.equals("实验") && method.equals("实验")){
 79             return true;
 80         }
 81         System.out.println(name+" : course type & access mode mismatch");
 82         return false;
 83     }
 84     //搜索课程
 85     public static Course searchCourse(String name){
 86         for (Course course:courses) {
 87             if(course.name.equals(name))
 88                 return course;
 89         }
 90         return null;
 91     }
 92     //添加成绩信息
 93     public static void scoreMessage(String string){
 94         String[] str = string.split(" ");
 95         String ID = str[0];
 96         String number = ID.substring(0,6);
 97         String name = str[1];
 98         String courseName = str[2];
 99 
100         Class cla;
101         //如果该班级第一次出现
102         if(searchClass(number) == null){
103             cla = new Class(number);
104             classes.add(cla);
105         }
106         //如果该班级存在
107         else {
108             cla = searchClass(number);
109         }
110 
111         Student student;
112         //如果该学生不存在
113         if(searchStudent(ID)==null){
114             student = new Student(ID,name);
115             students.add(student);
116             if (cla != null) {
117                 cla.addStudent(student);
118             }
119         }
120         //如果该学生存在
121         student = searchStudent(ID);
122 
123         //如果课程不存在
124         if(searchCourse(courseName)==null){
125             System.out.println(courseName+" does not exist");
126         }
127         //如果课程存在
128         else if(searchCourse(courseName)!=null){
129             Course course = searchCourse(courseName);
130             //考试
131             if(Objects.requireNonNull(course).method.equals("考试") && str.length == 5){
132                 int dailyScore = Integer.parseInt(str[3]);
133                 int finalScore = Integer.parseInt(str[4]);
134                 ExamScore score = new ExamScore(dailyScore,finalScore);
135                 Selection selection = new Selection(course,student,score);
136                 if (student != null && searchSelection(student, course) == null) {
137                     course.addSelection(selection);
138                     student.addSelection(selection);
139                 }
140             }
141             //考察
142              else if(course.method.equals("考察") && str.length == 4){
143                 int finalScore = Integer.parseInt(str[3]);
144                 AssessmentScore score = new AssessmentScore(finalScore);
145                 Selection selection = new Selection(course,student,score);
146                 if (student != null && searchSelection(student, course) == null) {
147                     course.addSelection(selection);
148                     student.addSelection(selection);
149                 }
150             }
151             //实验
152              else if(course.method.equals("实验")){
153                  int times = Integer.parseInt(str[3]);
154                  if(str.length == 4 + times){
155                      ExperimentScore score =new ExperimentScore();
156                      Selection selection = new Selection(course,student,score);
157                      for (int i=4; i<str.length; i++){
158                          score.addGrade(str[i]);
159                      }
160                      if (student != null && searchSelection(student, course) == null) {
161                          course.addSelection(selection);
162                          student.addSelection(selection);
163                      }
164                  }
165                  else{
166                     System.out.println(ID + " " + name + " : access mode mismatch");
167                 }
168             }
169             else {
170                 System.out.println(ID + " " + name + " : access mode mismatch");
171             }
172         }
173     }
174     public static Selection searchSelection(Student student,Course course){
175         for (Selection selection: student.selections){
176             if(selection.course.equals(course)){
177                 return selection;
178             }
179         }
180         return null;
181     }
182     public static Class searchClass(String number){
183         for (Class cla:classes) {
184             if(cla.number.equals(number)){
185                 return cla;
186             }
187         }
188         return null;
189     }
190     //搜索学生
191     public static Student searchStudent(String ID){
192         for (Student student:students) {
193             if(student.ID.equals(ID))
194                 return student;
195         }
196         return null;
197     }
198     //输出学生,课程,班级信息
199     public static void showMessage(){
200         Collections.sort(students);
201         for (Student stu:students) {
202             stu.printStudent();
203         }
204         Collections.sort(courses);
205         for (Course course:courses) {
206             course.printCourse();
207         }
208         Collections.sort(classes);
209         for (Class cla:classes) {
210             cla.printClass();
211         }
212     }
213     static class Match{
214          String stuNumMatch = "[0-9]{8}";//8个0-9的数字
215          String stuNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
216          String scoreMatch = "([1-9]?[0-9]|100)";
217          String courseNameMatch = "\\S{1,10}";//1到10个非空格(TAB)字符
218         String courseTypeMatch = "(选修|必修|实验)";
219          String checkCourseTypeMatch = "(考试|考察|实验)";
220         //courseInput用于定义课程信息模式(正则表达式)
221          String courseInput = courseNameMatch + " " + courseTypeMatch + " " + checkCourseTypeMatch;
222         //scoreInput用于定义成绩信息模式(正则表达式)
223          String scoreInput1 = stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch;         //考察
224          String scoreInput2 =  stuNumMatch + " " + stuNameMatch + " " + courseNameMatch + " " + scoreMatch + " " + scoreMatch;         //考试
225          String scoreInput3 = stuNumMatch + " " + stuNameMatch + " " + courseNameMatch;         //考察
226 
227         public int match(String string){
228 //            if (matchingScore(string))
229 //                return 2;
230             return matchingCourse(string);
231         }
232         //课程信息
233         // 1即格式正确,0即格式错误,-1即数量或者比重错误
234         private  int matchingCourse(String s) {
235             String[] str = s.split(" ");
236             int flag = 0;
237             if(str[2].equals("考察")){
238                 flag = assessmentCourseMatching(s);
239             }
240             if(str[2].equals("考试")){
241                 flag = examCourseMatching(s);
242             }
243             if(str[2].equals("实验")){
244                 flag = experimentCourseMatching(s);
245             }
246             return flag;
247         }
248         //考察
249         public  int assessmentCourseMatching(String s){
250             if(s.matches(courseInput))
251                 return 1;
252             return 0;
253         }
254         //考试
255         public  int examCourseMatching(String s){
256             String[] str = s.split(" ");
257             String courseLine = str[0] +" "+ str[1] +" "+ str[2];
258             if(courseLine.matches(courseInput)){
259                 double weight = Double.parseDouble(str[3])+Integer.parseInt(str[4]);
260                 if(weight==1){
261                     return 1;
262                 }
263                 else{
264                     System.out.println(str[0]+" : weight value error");
265                     return -1;
266                 }
267             }
268             return 0;
269         }
270         //实验
271         public  int experimentCourseMatching(String s){
272             String[] str = s.split(" ");
273             String courseLine = str[0] +" "+ str[1] +" "+ str[2];
274             if(courseLine.matches(courseInput)){
275                 double weight = 0;
276                 int n = Integer.parseInt(str[3]);
277                 if(4+n != str.length){
278                     System.out.println(str[0]+" : number of scores does not match");
279                     return -1;
280                 }
281                 for (int i=4; i<str.length; i++){
282                     weight += Double.parseDouble(str[i]);
283                 }
284                 if(weight==1){
285                     return 1;
286                 }
287                 else{
288                     System.out.println(str[0]+" : weight value error");
289                     return -1;
290                 }
291             }
292             return 0;
293         }
294         //成绩信息
295         private  boolean matchingScore(String s) {
296             int flag = matchingExperimentScore(s);
297             switch (flag){
298                 case 0:
299                     return true;
300                 case 1:
301                     return false;
302                 case 2:
303             }
304             return s.matches(scoreInput1) || s.matches(scoreInput2);
305         }
306 
307         private  int matchingExperimentScore(String s) {
308             String[] str = s.split(" ");
309             String courseName = str[2];
310             Course course = searchCourse(courseName);
311             if(course.method.equals("实验")){
312                 StringBuilder scoreInput = new StringBuilder(scoreInput3);
313                 for (int i=0; i<course.n; i++){
314                     scoreInput.append(" ").append(scoreMatch);
315                 }
316                 if(s.matches(scoreInput.toString())){
317                     return 0;
318                 }
319                 else {
320                     return 1;
321                 }
322             }
323             return 2;
324         }
325     }
326 }
327 /*班级*/
328 class Class implements Comparable<Class>{
329     String number;
330     ArrayList<Student> students = new ArrayList<>();
331     public Class(String number) {
332         this.number = number;
333     }
334     public void addStudent(Student student){
335         this.students.add(student);
336     }
337     public int getAverageScore(){
338         int sum = 0;
339         int n = students.size();
340         for (Student stu:students){
341             if(stu.selections.size() != 0){
342                 sum += stu.getAverageScore();
343             }
344             else {
345                 n--;
346             }
347         }
348         return sum /n;
349     }
350     public boolean scoreIsNull(){
351         for (Student stu:students) {
352             if(stu.selections.size()!=0){
353                 return false;
354             }
355         }
356         return true;
357     }
358     //输出班级信息
359     public void printClass(){
360         if(scoreIsNull()){
361             System.out.println(number+" has no grades yet");
362         }
363         else {
364             System.out.println(number+" "+getAverageScore());
365         }
366     }
367     //排列
368     @Override
369     public int compareTo(Class o) {
370         return number.compareTo(o.number);
371     }
372 }
373 /*学生*/
374 class Student implements Comparable<Student>{
375     String ID;
376     String name;
377     ArrayList<Selection> selections = new ArrayList<>();
378     public Student(String ID, String name) {
379         this.ID = ID;
380         this.name = name;
381     }
382     public void addSelection(Selection selection){
383         this.selections.add(selection);
384     }
385     //输出学生信息
386     public void printStudent(){
387         if(selections.size() == 0){
388             System.out.println(ID+" "+name+" did not take any exams");
389         }
390         else {
391             System.out.println(ID+" "+name+" "+getAverageScore());
392         }
393     }
394     //个人平均成绩
395     public int getAverageScore(){
396         int sum = 0;
397         for (Selection s : selections) {
398             sum += s.score.getScore();
399         }
400         return sum / selections.size();
401     }
402     //排列
403     @Override
404     public int compareTo(Student o) {
405         return this.ID.compareTo(o.ID);
406     }
407 }
408 /*选课*/
409 class Selection{
410     Course course;
411     Student student;
412     Score score;
413     public Selection(Course course, Student student, Score score) {
414         this.course = course;
415         this.student = student;
416         this.score = score;
417     }
418 }
419 /*课程*/
420 class Course implements Comparable<Course>{
421     String name;
422     String nature;
423     String method;
424     int n = 0;
425     double[] weights;
426     ArrayList<Selection> selections = new ArrayList<>();
427     public Course(String name, String nature, String method) {
428         this.name = name;
429         this.nature = nature;
430         this.method = method;
431     }
432     public void setWeights(int n,double[] weights){
433         this.n = n;
434         this.weights = weights;
435     }
436     public void addSelection(Selection selection){
437         this.selections.add(selection);
438     }
439     public int getAverageDailyScore(){
440         int sum = 0;
441         for (Selection s:selections) {
442             sum += s.score.getDailyScore();
443         }
444         return sum /selections.size();
445     }
446     public int getAverageFinalScore(){
447         int sum = 0;
448         for (Selection s:selections) {
449             sum += s.score.getFinalScore();
450         }
451         return sum /selections.size();
452     }
453     public int getAverageScore(){
454         int sum = 0;
455         for (Selection s:selections){
456             sum += s.score.getScore();
457         }
458         return sum/selections.size();
459     }
460     public void printCourse(){
461         if(selections.size() == 0){
462             System.out.println(name+" has no grades yet");
463         }
464         else if(method.equals("考察")){
465             System.out.println(name+" "+getAverageFinalScore()+" "+getAverageScore());
466         }
467         else if(method.equals("考试")){
468             System.out.println(name+" "+getAverageDailyScore()+" "+getAverageFinalScore()+" "+getAverageScore());
469         }
470         else if(method.equals("实验")){
471             System.out.println(name+" "+getAverageScore());
472         }
473     }
474     public int compareTo(Course o) {
475         Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);
476         return compare.compare(name,o.name);
477     }
478 }
479 /*成绩*/
480 class Score{
481     public int getScore(){
482         return 0;
483     }
484     public int getDailyScore() {
485         return 0;
486     }
487     public int getFinalScore() {
488         return 0;
489     }
490 
491 }
492 /*考察成绩*/
493 class AssessmentScore extends Score{
494     int finalScore;
495     public AssessmentScore(int finalScore) {
496         this.finalScore = finalScore;
497     }
498     public int getFinalScore() {
499         return finalScore;
500     }
501     public int getScore(){
502         return finalScore;
503     }
504 }
505 /*考试成绩*/
506 class ExamScore extends Score{
507     int dailyScore;
508     int finalScore;
509     public ExamScore(int dailyScore, int finalScore) {
510         this.dailyScore = dailyScore;
511         this.finalScore = finalScore;
512     }
513     public int getDailyScore() {
514         return dailyScore;
515     }
516     public int getFinalScore() {
517         return finalScore;
518     }
519     public int getScore(){
520         return (int) (0.3*dailyScore+0.7*finalScore);
521     }
522 }
523 /*实验成绩*/
524 class ExperimentScore extends Score{
525     ArrayList<Integer> grades = new ArrayList<>();
526     public ExperimentScore() {
527     }
528     public void addGrade(String grade){
529         this.grades.add(Integer.parseInt(grade));
530     }
531     public int getScore() {
532         int sum = 0;
533         for (int grade:grades) {
534             sum += grade;
535         }
536         return sum /grades.size();
537     }
538 }
课程成绩统计程序-3
 1 import java.util.ArrayList;
 2 import java.util.Collections;
 3 import java.util.Scanner;
 4 
 5 public class Main {
 6     public static void main(String[] args){
 7         ArrayList<Identity> identities = new ArrayList<>();
 8         Scanner input = new Scanner(System.in);
 9         int n = Integer.parseInt(input.nextLine());
10         for (int i=0; i<n; i++){
11             String str = input.nextLine();
12             Identity identity = new Identity(str);
13             identities.add(identity);
14         }
15         Collections.sort(identities);
16         String str = input.nextLine();
17         while (!str.equals("e")){
18             if(str.equals("sort1")){
19                 for (Identity identity:identities) {
20                     System.out.println(identity.sort1());
21                 }
22             }
23             if(str.equals("sort2")){
24                 for (Identity identity:identities) {
25                     identity.sort2();
26                 }
27             }
28             str = input.nextLine();
29         }
30         System.out.println("exit");
31     }
32 }
33 class Identity implements Comparable<Identity>{
34     String ID;
35 
36     public Identity(String ID) {
37         this.ID = ID;
38     }
39     public String sort1(){
40         String year = ID.substring(6,10);
41         String month = ID.substring(10,12);
42         String day = ID.substring(12,14);
43         return year+"-"+month+"-"+day;
44     }
45     public void sort2(){
46         System.out.println(ID);
47     }
48     @Override
49     public int compareTo(Identity o) {
50         return -o.sort1().compareTo(sort1());
51     }
52 }
jmu-Java-02基本语法-03-身份证排序
 1 import java.util.Arrays;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     public static void main(String[] args) {
 6         Scanner input = new Scanner(System.in);
 7         int n = Integer.parseInt(input.nextLine());
 8         ArrayIntegerStack stack = new ArrayIntegerStack(n);
 9         int m = Integer.parseInt(input.nextLine());
10         for (int i = 0; i < m; i++){
11             String str = input.next();
12             System.out.println(stack.push(str));
13         }
14         System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
15         System.out.println(Arrays.toString(stack.data));
16         int x = Integer.parseInt(input.next());
17         for (int i = 0; i < x; i++){
18             System.out.println(stack.pop());
19         }
20         System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
21         System.out.println(Arrays.toString(stack.data));
22     }
23 }
24 interface IntegerStack{
25     String push(String item);
26     //如果item为null,则不入栈直接返回null。如果栈满,也返回null。如果插入成功,返回item。
27 
28     String pop();   //出栈,如果为空,则返回null。出栈时只移动栈顶指针,相应位置不置为null
29     String peek();  //获得栈顶元素,如果为空,则返回null.
30     int size();      //返回栈中元素个数
31     boolean empty();
32 }
33 class ArrayIntegerStack implements IntegerStack{
34     int top = -1;
35     int size;
36     String[] data;
37     public ArrayIntegerStack(int size){
38         this.initData(size);
39     }
40     public void initData(int size){
41         this.size = size;
42         this.data = new String[size];
43     }
44     //添加元素
45     @Override
46     public String push(String value) {
47         //数组越界
48         if(this.top >= this.size - 1)
49             return null;
50         this.top ++;
51         this.data[this.top] = value;
52         return value;
53     }
54     //移除栈顶元素
55     @Override
56     public String pop() {
57         if(top == -1)
58             return null;
59         String item = this.data[this.top];
60         top --;
61         return item;
62     }
63     //获取栈顶元素
64     @Override
65     public String peek() {
66         if(top == -1)
67             return null;
68         return this.data[this.top];
69     }
70     @Override
71     public int size() {
72         return this.top+1;
73     }
74 
75     @Override
76     public boolean empty() {
77         return top == -1;
78     }
79 
80 }
jmu-Java-04面向对象进阶-03-接口-自定义接口ArrayIntegerStack
 1 import java.util.ArrayList;
 2 import java.util.Arrays;
 3 import java.util.Scanner;
 4 
 5 public class Main {
 6     static ArrayList<PersonOverride> person1 = new ArrayList<>();
 7     static ArrayList<PersonOverride> person2 = new ArrayList<>();
 8     public static void main(String[] args) {
 9         Scanner input = new Scanner(System.in);
10         //person1
11         int n1 = Integer.parseInt(input.nextLine());
12         for(int i=0; i<n1; i++){
13             PersonOverride person = new PersonOverride();
14             person1.add(person);
15         }
16         //person2
17         int n2 = Integer.parseInt(input.nextLine());
18         for (int i=0; i<n2; i++){
19             String line = input.nextLine();
20             String[] strings = line.split(" ");
21             String name = strings[0];
22             int age = Integer.parseInt(strings[1]);
23             boolean gender = Boolean.parseBoolean(strings[2]);
24             PersonOverride person = new PersonOverride(name,age,gender);
25             addPerson2(person);
26         }
27         //输出
28         for (PersonOverride person:person1) {
29             System.out.println(person.toString());
30         }
31         for (PersonOverride person:person2) {
32             System.out.println(person.toString());
33         }
34         System.out.println(person2.size());
35         System.out.println(Arrays.toString(PersonOverride.class.getConstructors()));
36     }
37     public static void addPerson2(PersonOverride person){
38         for (PersonOverride per:person2) {
39             if(person.equals(per)){
40                 return;
41             }
42         }
43         person2.add(person);
44     }
45 }
46 class PersonOverride{
47     private String name;
48     private int age;
49     private boolean gender;
50     public PersonOverride() {
51         this.name = "default";
52         this.age = 1;
53         this.gender = true;
54     }
55     public PersonOverride(String name, int age, boolean gender) {
56         this.name = name;
57         this.age = age;
58         this.gender = gender;
59     }
60     public String toString(){
61         return name+"-"+age+"-"+gender;
62     }
63     public boolean equals(PersonOverride person) {
64         if(name.equals(person.name))
65             if(age==person.age)
66                 if(gender==person.gender)
67                     return true;
68         return false;
69     }
70 }
jmu-Java-03面向对象基础-05-覆盖

三、踩坑心得

有一次数据是对的,但对不上测试点,原来是因为格式问题,但这个格式问题也没有明确标注在题目中,有时候希望老师把测试点放出来,否则不知道哪里错了。

一开始比较容易错的地方就是方法设计得太复杂太少,或者注释行太少,导致下次改进时看不懂。

在不知道如何实现某种操作时,使用浏览器是非常重要的,很少有人能够记住所有代码操作,也有可能别人的方法更便捷。

四、改进建议

我觉得代码应该多一些注释行,以便于下次再看和修改,代码最好多用方法和类,以免代码过于繁杂而看不懂

五、总结

我觉得这次的成绩系统练习题让我学到了许多,因为上次的菜单类题目我没有认真对待,导致错过了很多,而这次的学生成绩系统题目与之前的菜单提有许多相似之处,所以这次的题目相当于再给我一次机会。认真对待这次的题目,我学到了很多,让我也能够轻松地通过期末考试。

希望老师对于测试点方面的问题有所考量,有时候不能通过测试点并非因为数据方面的错误,是含有题目所未包含的格式问题,导致我很苦恼,有一次仅有一个测试点不通过,应该不是数据问题

 
posted @ 2023-06-28 15:42  230523  阅读(37)  评论(0)    收藏  举报