首页 > 其他分享 >blog

blog

时间:2023-06-21 14:14:20浏览次数:26  
标签:String int blog num split new data

import java.text.Collator;
import java.util.*;

class Course {
String name;
String type;
String mode;

Course(String name, String type, String mode) {
this.name = name;
this.type = type;
this.mode = mode;
}
}

class Grade {
String studentId;
String name;
String courseName;
int dailyGrade;
int finalGrade;

Grade(String studentId, String name, String courseName, int dailyGrade, int finalGrade) {
this.studentId = studentId;
this.name = name;
this.courseName = courseName;
this.dailyGrade = dailyGrade;
this.finalGrade = finalGrade;
}
}

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Course> courses = new ArrayList<>();
List<Grade> grades = new ArrayList<>();

int flag = 1;
String studentinput = "";

// 读取课程信息
f1: while (scanner.hasNext()) {

 


try {

String input = scanner.nextLine();

if (input.equals("end")) {
flag = 0;
break;
}
String[] courseInfo = input.split(" ");

if(courseInfo.length > 3){
studentinput = input;
break;
}

String courseName = courseInfo[0];
String courseType = courseInfo[1];
String courseMode = courseInfo[2];


for (Course cours : courses) {
if(cours.name.equals(courseName)){

if(cours.type.equals("必修")&&cours.mode.equals("考察")) {
continue ;
}
continue f1;
}

}

if(courseName.length() > 10 ){
System.out.println("wrong format");
continue ;
}

courses.add(new Course(courseName, courseType, courseMode));
}catch (Exception e){
System.out.println("wrong format");
}


}

// 读取成绩信息
f2: while (flag != 0 && scanner.hasNext()) {


try {
String input = "";
if(studentinput==""){
input = scanner.nextLine();
}else input = studentinput;

studentinput = "";

if ( input.equals("end")) {
break;
}
String[] gradeInfo = input.split(" ");
String studentId = gradeInfo[0];
String name = gradeInfo[1];
String courseName = gradeInfo[2];


if(gradeInfo[3].contains(".")){
System.out.println("wrong format");
continue ;
}

if(gradeInfo.length > 4){
if(gradeInfo[4].contains(".")){
System.out.println("wrong format");
continue ;
}
}

int dailyGrade = gradeInfo.length > 4 ? Integer.parseInt(gradeInfo[3]) : -1;
int finalGrade = Integer.parseInt(gradeInfo[gradeInfo.length - 1]);

Grade grade = new Grade(studentId, name, courseName, dailyGrade, finalGrade);

for (Grade grade1 : grades) {
if(grade1.studentId.equals(grade.studentId)&& grade1.name.equals(grade.name)&& grade1.courseName.equals(grade.courseName)){
continue f2;
}
}

 

 

if(studentId.length() != 8 || name.length() > 10 || courseName.length() > 10 ) {
System.out.println("wrong format");
continue ;
}

grades.add(grade);


}catch (Exception e){
System.out.println("wrong format");
}

}


// 计算课程成绩平均分
Map<String, List<Grade>> courseGrades = new HashMap<>();

//平时平均分
Map<String, Integer> courseDailyAverages = new HashMap<>();

//期末平均分
Map<String, Integer> courseFinalAverages = new HashMap<>();

//总平均分
Map<String, Integer> courseTotalAverages = new HashMap<>();

 

for(int i = 0; i < courses.size(); i++){

if(courses.get(i).type.equals("必修") && courses.get(i).mode.equals("考察")){
System.out.println(courses.get(i).name + " : course type & access mode mismatch");
courses.remove(courses.get(i));

if(i == courses.size() -1 ){
break;
}

}

 

}


for ( Grade grade : grades) {

String courseName = grade.courseName;

// if (!isCourseExist(courseName, courses)) {
// System.out.println(grade.studentId + " " + grade.name + " : " + courseName + " does not exist");
// grade.finalGrade = -1;
//
// continue;
// }

Course course = getCourse(courseName, courses);

 

int flag4 = 0;
for (Course cours : courses) {
if(cours.name.equals(courseName)){
flag4 = 1;
}
}

 

if(flag4 == 0){
System.out.println(courseName + " does not exist");
grade.finalGrade = -1;
continue;
}


if (course.type.equals("必修")&& grade.dailyGrade == -1) {
System.out.println(grade.studentId + " " + grade.name + " : access mode mismatch");
grade.finalGrade = -1;
continue;
}

 

//根据课程名字,插入所有成员课程成绩列表
courseGrades.putIfAbsent(courseName, new ArrayList<>());
courseGrades.get(courseName).add(grade);


if(grade.finalGrade < 0 || grade.finalGrade > 100){
System.out.println("wrong format");
}else {

//获取录入成绩的平均分之和
if (grade.dailyGrade > 0) {
int dailyAverage = courseDailyAverages.getOrDefault(courseName, 0);
dailyAverage += grade.dailyGrade;
courseDailyAverages.put(courseName, dailyAverage);
}

//获取录入成绩的期末之和
int finalAverage = courseFinalAverages.getOrDefault(courseName, 0);
finalAverage += grade.finalGrade;
courseFinalAverages.put(courseName, finalAverage);


// 获取录入成绩的总之和
int totalAverage = courseTotalAverages.getOrDefault(courseName, 0);
totalAverage += grade.dailyGrade > 0 ? (int) (grade.dailyGrade * 0.3 + grade.finalGrade * 0.7) : grade.finalGrade;
courseTotalAverages.put(courseName, totalAverage);

}

}

 

 

// 计算学生总成绩和平均分
Map<String, List<Grade>> studentGrades = new HashMap<>();
Map<String, Integer> studentTotals = new HashMap<>();
Map<String, Integer> studentCounts = new HashMap<>();
for (Grade grade : grades) {

//获取每个学生的总成绩list
String studentKey = grade.studentId + " " + grade.name;
studentGrades.putIfAbsent(studentKey, new ArrayList<>());
studentGrades.get(studentKey).add(grade);


//总成绩
int total = studentTotals.getOrDefault(studentKey, 0);
total += grade.dailyGrade > 0 ? (int) (grade.dailyGrade * 0.3 + grade.finalGrade * 0.7) : grade.finalGrade;
studentTotals.put(studentKey, total);

//成绩的个数
int count = studentCounts.getOrDefault(studentKey, 0);
count++;
studentCounts.put(studentKey, count);
}

 

// 输出学生总成绩平均分
List<String> studentAverages = new ArrayList<>();
for (String studentKey : studentGrades.keySet()) {
int total = studentTotals.get(studentKey);
int count = studentCounts.get(studentKey);
int average = total / count;

String[] studentInfo = studentKey.split(" ");
String studentAverage = studentInfo[0] + " " + studentInfo[1] + " " + average;


studentAverages.add(studentAverage);
}

//对总成绩平均分进行排序
studentAverages.sort(Comparator.comparingInt(s -> Integer.parseInt(s.split(" ")[0])));


// 输出学生总成绩平均分
for (String studentAverage : studentAverages) {


int flag1 = 0;
if(Integer.parseInt(studentAverage.split(" ")[2]) < 0 &&Integer.parseInt(studentAverage.split(" ")[2]) != -1 || Integer.parseInt(studentAverage.split(" ")[2]) > 100 ){

continue;
}

if(Integer.parseInt(studentAverage.split(" ")[2]) != -1){
flag1 = 1;
System.out.println(studentAverage);
}

if(flag1 == 0){
System.out.println(studentAverage.split(" ")[0] + " " + studentAverage.split(" ")[1] + " did not take any exams");
}
}


// 输出课程成绩平均分
List<String> courseAverages = new ArrayList<>();

for (Course course : courses) {
String courseName = course.name;
int dailyAverage = courseDailyAverages.getOrDefault(courseName, -1);
int finalAverage = courseFinalAverages.getOrDefault(courseName, -1);
int totalAverage = courseTotalAverages.getOrDefault(courseName, -1);

int count = 0;
for (Grade grade : grades) {
if(grade.courseName.equals(courseName)){
count ++;
}
}

String courseAverage;
if (dailyAverage == -1 && finalAverage == -1 && totalAverage == -1) {
courseAverage = courseName + " has no grades yet";
} else {
if(dailyAverage != -1){
courseAverage = courseName + " " + dailyAverage/count + " " + finalAverage/count + " " + totalAverage/count;
}else courseAverage = courseName + " " + finalAverage/count + " " + totalAverage/count;
}
courseAverages.add(courseAverage);
}


// 按照课程名称的字符顺序排序
Collator collator = Collator.getInstance(Locale.CHINA);
courseAverages.sort(Comparator.comparing(s -> s.split(" ")[0], collator));


// 输出课程成绩平均分
for (String courseAverage : courseAverages) {
System.out.println(courseAverage);
}

// 计算班级总成绩平均分
Map<String, Integer> classTotals = new HashMap<>();
Map<String, Integer> classCounts = new HashMap<>();
for (List<Grade> classGrades : studentGrades.values()) {
if (classGrades.isEmpty()) {
continue;
}
String classKey = classGrades.get(0).studentId.substring(0, 6);
int total = classTotals.getOrDefault(classKey, 0);
int count = classCounts.getOrDefault(classKey, 0);

for (Grade grade : classGrades) {
int gradeTotal = grade.dailyGrade > 0 ? (int) (grade.dailyGrade * 0.3 + grade.finalGrade * 0.7) : grade.finalGrade;
total += gradeTotal;
count++;
}
classTotals.put(classKey, total);
classCounts.put(classKey, count);
}

// 输出班级总成绩平均分
List<String> classAverages = new ArrayList<>();
for (String classKey : classTotals.keySet()) {
int total = classTotals.get(classKey);
int count = classCounts.get(classKey);
int average = total / count;
String classAverage = classKey + " " + average;


classAverages.add(classAverage);
}
classAverages.sort(Comparator.comparing(s -> s.split(" ")[0]));

// 输出班级总成绩平均分
for (String classAverage : classAverages) {

if(Integer.parseInt(classAverage.split(" ")[1]) < 0 && Integer.parseInt(classAverage.split(" ")[1]) != -1 || Integer.parseInt(classAverage.split(" ")[1]) >100){
continue;
}

if(Integer.parseInt(classAverage.split(" ")[1]) != -1) {
System.out.println(classAverage);
}else System.out.println(classAverage.split(" ")[0] + " has no grades yet");

}
}

// 判断课程是否存在
private static boolean isCourseExist(String courseName, List<Course> courses) {
for (Course course : courses) {
if (course.name.equals(courseName)) {
return true;
}
}
return false;
}

// 获取课程对象
private static Course getCourse(String courseName, List<Course> courses) {
for (Course course : courses) {
if (course.name.equals(courseName)) {
return course;
}
}
return null;
}

}

 

import java.util.HashMap;
import java.util.TreeMap;
import java.util.*;
public class Main{
public static void main(String[] args){
TreeMap<String,HashMap<String,String>> students = new TreeMap<>(((o1, o2) -> {
if(o1.compareTo(o2)>0)
return -1;
else if(o1.compareTo(o2)<0)
return 1;
else
return 0;
}));
Scanner sc = new Scanner(System.in);
String tem = null;
HashMap<String,shb> Sites=new HashMap<String,shb>();
while(true){
tem = sc.nextLine();
if(tem.equals("end")){
break;
}
String[] tem1 = tem.split(" ");
shb sb=new shb();
sb.shbwd(tem1[1],tem1[2]);
students.put(tem1[0], sb);}
students.forEach((key,value)->{
students.get(key).forEach((key1,value1)->{
System.out.println(key+" "+key1+" "+value1);
});
});
}
}


class shb extends HashMap<String, String> {
String xm;
String cj;
public void shbwd(String xm,String cj ){
this.xm=xm;
this.cj=cj;
}
}

import java.util.HashMap;
import java.util.ArrayList;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String tem = null;
HashMap<String,shb> map=new HashMap<String,shb>();
while(true){
tem = sc.nextLine();
if(tem.equals("end")){
break;
}
String[] tem1 = tem.split(" ");
shb sb=new shb();
sb.shbwd(tem1[0],tem1[1],tem1[2]);
map.put(tem1[0],sb);}
List<Map.Entry<String,shb>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String,shb>>() {
public int compare(Map.Entry<String, shb> e1,
Map. Entry<String, shb> e2) {
return e2.getValue().xh.compareTo(e1.getValue().xh);
}
});
for(Map.Entry<String, shb> hb: list){
System.out.println(hb.getValue().xh+" "+hb.getValue().xm+" "+hb.getValue().cj);
}
}
}


class shb {
String xh;
String xm;
String cj;
public void shbwd(String xh,String xm,String cj ){
this.xh=xh;
this.xm=xm;
this.cj=cj;
}
}

import java.util.*;
import java.text.Collator;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);

final String regex0 = "^[\\u4E00-\\u9FA5A-Za-z0-9]{1,10} +(必修|选修|实验)? *(考试|考察|实验)?$";
final String regex1 = "^\\d{8}\\s+[\\u4E00-\\u9FA5A-Za-z]{1,10}\\s+[\\u4E00-\\u9FA5A-Za-z0-9]{1,10}\\s*((100)|(\\d{1,2})|(0))?\\s+((100)|(\\d{1,2})|(0))$";
final String regex2 = "^\\d{8}\\s[\\u4e00-\\u9fa5a-zA-Z ]{1,10}\\s[\\u4e00-\\u9fa5a-zA-Z0-9 ]{1,10}\\s[4-9]\\s((100)|([1-9]\\d)|\\d)(\\s((100)|([1-9]\\d)|\\d)){1,20}$";
DataMessage data = new DataMessage();
Calculate calculate = new Calculate();
while (true) {
String input = scn.nextLine();
if (input.equals("end")) {
break;
}
InputProcessor inputProcessor = new InputProcessor();
if (!input.matches(regex0)) {
if (input.matches(regex1)||input.matches(regex2)) {
inputProcessor.ScoresProcessor(data,input);
} else {
System.out.println("wrong format");
}
} else {
inputProcessor.CourseProcessor(data,input);
}
}
calculate.Stu_SingelGrade(data);
calculate.All_CourseAverage(data);
calculate.Single_CourseAverage(data);
calculate.All_classAverage(data);


}
}
class InputProcessor {
void CourseProcessor(DataMessage data,String input) {
String[] split = input.split(" ");
if ((!split[1].equals("必修") || !split[2].equals("考试")) && (!split[1].equals("选修") || split[0].equals("实验")) && (!split[1].equals("实验") || !split[2].equals("实验"))) {
System.out.println(split[0] + " : course type & access mode mismatch");
} else {
data.setCourses(split[0], split[1], split[2]);
}
}
void ScoresProcessor(DataMessage data,String input){
String[] split = input.split(" ");
data.setClasses(split[0].substring(0,6));
data.setStudents(split[0].substring(0, 6), split[1], split[0]);
if (data.courses.containsKey(split[2])) {
if (!data.courses.get(split[2]).type.equals("选修")) {
if (data.courses.get(split[2]).type.equals("必修")) if (split.length != 5) {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSelectCourse(split[0], split[2], "no access", "no access");
} else {
data.setSelectCourse(split[0], split[2], split[3], split[4]);
}
else if (data.courses.get(split[2]).type.equals("实验")) {
if (Integer.parseInt(split[3]) < 4 || Integer.parseInt(split[3]) > 9 || split.length != 4 + Integer.parseInt(split[3])) {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSingleGrade(split[0], split[2], "num wrong", "no access");
} else {
data.setSingleGrade(split[0], split[2], split[3], input);
}
}
} else {
if (!data.courses.get(split[2]).test_way.equals("考试") || split.length != 5) {
if (data.courses.get(split[2]).test_way.equals("考察") && split.length == 4)
data.setSelectCourse(split[0], split[2], split[3]);
else {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSelectCourse(split[0], split[2], "no access", "no access");
}
} else {
data.setSelectCourse(split[0], split[2], split[3], split[4]);
}
}
} else {
System.out.println(split[2] + " does not exist");
data.setSelectCourse(split[0], split[2], "no access", "no access");
}
}

}
class Calculate{
final float weight0 = 0.3F;
final float weight1 = 0.7F;
void Stu_SingelGrade(DataMessage data) {
for (Map.Entry<String, Class> stringClassEntry : data.classes.entrySet()) {
Class aClass = stringClassEntry.getValue();
aClass.students.forEach((name, student) -> data.StuSelectCourse.get(student.num).gradeMap.forEach((key, value) -> {
if (value instanceof Examination && ((Examination) value).normalScore.matches("\\d+") && ((Examination) value).endScore.matches("\\d+")) {
value.totalScores = String.valueOf((int) (weight0 * Integer.parseInt(((Examination) value).normalScore)
+ weight1 * Integer.parseInt(((Examination) value).endScore)));
} else if (value instanceof inspect && ((inspect) value).endScore.matches("\\d+")) {
value.totalScores = ((inspect) value).endScore;
} else if (value instanceof experiment && ((experiment) value).num.matches("\\d+")) {
int count = Integer.parseInt(((experiment) value).num);
int sum = 0;
for (Integer score : ((experiment) value).grades) {
sum += score;
}
value.totalScores = String.valueOf(sum / count);
}
}));
}
}

void All_CourseAverage(DataMessage data) {
data.classes.forEach((cla_num,Class1)-> Class1.students.forEach((stu_num, student)->{
int count = 0;int sum = 0;
for (Map.Entry<String, Score> entry : data.StuSelectCourse.get(stu_num).gradeMap.entrySet()) {
Score value = entry.getValue();
if(Integer.parseInt(value.totalScores)>=0) {
count++;
sum += Integer.parseInt(value.totalScores);
}
}
if(count!=0)
System.out.println(stu_num+" "+Class1.students.get(stu_num).name+" "+ (sum/count));
else
System.out.println(stu_num+" "+Class1.students.get(stu_num).name+" "+"did not take any exams");
}));
}

public void Single_CourseAverage(DataMessage data) {
for (Map.Entry<String, Course> course : data.courses.entrySet()) {
String key = course.getKey();
Course v = course.getValue();
int[] tem = new int[3];
int count = 0;
for (Map.Entry<String, SelectCourse> e : data.StuSelectCourse.entrySet()) {
SelectCourse value1 = e.getValue();
for (Map.Entry<String, Score> entry : value1.gradeMap.entrySet()) {
String key2 = entry.getKey();
Score value2 = entry.getValue();
if (key2.equals(key)) {
if (Integer.parseInt(value2.totalScores) >= 0) {
count++;
tem[2] += Integer.parseInt(value2.totalScores);
if (value2 instanceof Examination) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] += Integer.parseInt(((Examination) value2).normalScore);
tem[1] += Integer.parseInt(((Examination) value2).endScore);
}
} else if (value2 instanceof inspect) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] = -100;
tem[1] += Integer.parseInt(((inspect) value2).endScore);
}
} else if (value2 instanceof experiment) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] = -100;
tem[1] += tem[1] += Integer.parseInt(value2.totalScores);
}
}
}
}
}
}
if (count != 0) {
for (int i = 0; i < 3; i++) {
tem[i] = tem[i] / count;
}
} else {
for (int i = 0; i < 3; i++) {
tem[i] = -100;
}
}
if (tem[0] < 0 && tem[1] < 0 && tem[2] < 0) {
System.out.println(key + " has no grades yet");
} else {
String x = key + " " + tem[0] + " " + tem[1] + " " + tem[2];
if (v.type.equals("选修")) {
if (v.test_way.equals("考察"))
System.out.println(key + " " + tem[1] + " " + tem[2]);
else
System.out.println(x);
} else {
if (v.type.equals("必修")) {
System.out.println(x);
} else if (v.type.equals("实验")) {
System.out.println(key + " " + tem[2]);
}
}
}
}
}

public void All_classAverage(DataMessage data) {
for (Map.Entry<String, Class> stringClassEntry : data.classes.entrySet()) {
String num = stringClassEntry.getKey();
Class Class = stringClassEntry.getValue();
int tem;
int sum = 0;
int count = 0;
for (Map.Entry<String, Student> mapEntry : data.classes.get(num).students.entrySet()) {
Student value = mapEntry.getValue();
for (Map.Entry<String, SelectCourse> e : data.StuSelectCourse.entrySet()) {
String key1 = e.getKey();
SelectCourse value1 = e.getValue();
if (key1.equals(value.num)) {
for (Map.Entry<String, Score> entry : value1.gradeMap.entrySet()) {
Score gra = entry.getValue();
if (Integer.parseInt(gra.totalScores) >= 0) {
sum += Integer.parseInt(gra.totalScores);
count++;
}
}
}
}
}
if (count != 0)
tem = sum / count;
else
tem = -100;
if (tem >= 0) {
System.out.println(num + " " + tem);
} else
System.out.println(num + " has no grades yet");
}
}
}
class Class {
String num;
TreeMap<String, Student> students = new TreeMap<>();
Class(String num){
this.num = num;
}
}
class Course {
String type;
String test_way;
String name;
Course(String name,String type, String test_way){
this.type = type;
this.name = name;
this.test_way = test_way;
}
}
class Student {
String name;
String num;
Student(String name, String num) {
this.name = name;
this.num = num;
}
}
class SelectCourse {
String num;//学生
TreeMap<String,Score> gradeMap =new TreeMap<>();
SelectCourse(String stuNum, String courseName, String normalScore, String testScore)
{
this.num = stuNum;
gradeMap.put(courseName,new Examination(normalScore,testScore));

}
public SelectCourse()
{

}
SelectCourse(String stuName, String courseName, String endScore)
{
this.num = stuName;
gradeMap.put(courseName,new inspect(endScore));
}

 

void SetGrade(String courseName, String normalScore, String endScore)
{
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName, new Examination(normalScore,endScore));
}
void SetGrade(String courseName, String test_score)
{
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName,new inspect(test_score));
}
void setLabStuMes(String stuNum, String courseName, String labNum, ArrayList<Integer> scores){
this.num = stuNum;
gradeMap.put(courseName,new experiment(labNum,scores));
}
void setLabGrade(String courseName, String labNum, ArrayList<Integer> scores){
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName,new experiment(labNum,scores));
}

}
class experiment extends Score{
String num;
ArrayList<Integer> grades;
experiment(String num, ArrayList<Integer> Scores){
this.num = num;
this.grades = Scores;
}
}
class DataMessage {
TreeMap<String, Course> courses = new TreeMap<>(DataMessage::compare);
TreeMap<String, Class> classes = new TreeMap<>();
TreeMap<String, SelectCourse> StuSelectCourse = new TreeMap<>(DataMessage::compare2);

DataMessage() {

}

static int compare(String o1, String o2) {
return compare2(o1, o2);
}
static int compare2(String o1, String o2) {

try {
Comparator<Object> comparator = Collator.getInstance(Locale.CHINA);
if (comparator.compare(o1, o2) < 0) return -1;
else if (comparator.compare(o1, o2) > 0) return 1;
} catch (Exception ignored) {

}
return 0;
}

void setCourses(String name, String type, String test_way) {
if (courses.containsKey(name)) return;
courses.put(name, new Course(name, type, test_way));
}

void setClasses(String num) {
if (!classes.containsKey(num)) classes.put(num, new Class(num));
}

void setStudents(String clas_num, String name, String num) {
if (!classes.containsKey(clas_num)) return;
classes.get(clas_num).students.put(num, new Student(name, num));
}

void setSelectCourse(String num, String courseName, String normalScore, String endScore) {
if (StuSelectCourse.containsKey(num)) StuSelectCourse.get(num).SetGrade(courseName, normalScore, endScore);
else {
StuSelectCourse.put(num, new SelectCourse(num, courseName, normalScore, endScore));
}
}

void setSelectCourse(String num, String courseName, String endScore) {
if (!StuSelectCourse.containsKey(num)) StuSelectCourse.put(num, new SelectCourse(num, courseName, endScore));
else {
StuSelectCourse.get(num).SetGrade(courseName, endScore);
}
}
void setSingleGrade(String stuNum, String courseName, String labNum, String grades){
ArrayList<Integer> scores;
String[] tem = grades.split(" ");
scores = IntStream.range(4, tem.length).filter(i -> tem[i].matches("\\d+")).mapToObj(i -> Integer.parseInt(tem[i])).collect(Collectors.toCollection(ArrayList::new));
if (StuSelectCourse.containsKey(stuNum)) {
StuSelectCourse.get(stuNum).setLabGrade(courseName,labNum,scores);
} else {
SelectCourse tem_stu_mes = new SelectCourse();
tem_stu_mes.setLabStuMes(stuNum,courseName,labNum,scores);
StuSelectCourse.put(stuNum,tem_stu_mes);
}
}

}
class Examination extends Score
{
String normalScore;
String endScore;
Examination(String normalScore, String endScore) {
this.normalScore = normalScore;
this.endScore = endScore;
}
}
class inspect extends Score{
String endScore;
inspect(String endScore) {
this.endScore = endScore;
}
}
abstract class Score {
String totalScores = "-100";
}

 

//动物发生模拟器
public class Main {
public static void main(String[] args) {
Cat cat = new Cat();
Dog dog = new Dog();
Goat goat = new Goat();
speak(cat);
speak(dog);
speak(goat);
}
//定义静态方法speak()
public static void speak(Animal animal){
System.out.println(animal.getAnimalClass()+"的叫声:"+animal.shout());
}

}

//定义抽象类Animal
abstract class Animal{
public abstract String getAnimalClass();
public abstract String shout();
}
//基于Animal类,定义猫类Cat,并重写两个抽象方法
class Cat extends Animal{
public String getAnimalClass(){
return "猫";
}
public String shout(){
return "喵喵";
}
}
//基于Animal类,定义狗类Dog,并重写两个抽象方法
class Dog extends Animal{
public String getAnimalClass(){
return "狗";
}
public String shout(){
return "汪汪";
}
}
//基于Animal类,定义山羊类Goat,并重写两个抽象方法
class Goat extends Animal{
public String getAnimalClass(){
return "山羊";
}
public String shout(){
return "咩咩";
}
}

import java.util.ArrayList;
import java.util.*;
import java.util.List;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String tem = null;
List<shb> data = new ArrayList<>();
while(true){
tem = sc.nextLine();
if(tem.equals("end")){
break;
}
String[] tem1 = tem.split(" ");
shb sb=new shb();
sb.shbwd(tem1[0],tem1[1],Integer.parseInt(tem1[2])+Integer.parseInt(tem1[3]));
data.add(sb);}
Collections.sort(data, new Comparator<shb>() {
public int compare(shb o1, shb o2) {
if(o1.hh() - o2.hh()>0)
return -1;
else if (o1.hh() - o2.hh()<0)
return 1;
else
return 0;

}
});
for(shb p:data) {
System.out.println(p.xh+" "+p.xm+" "+p.ss);
}
}
}
class shb{
String xh;
String xm;
int ss;
public void shbwd(String xh, String xm, int ss) {
this.xh = xh;
this.xm = xm;
this.ss = ss;
}
public int hh() {
return ss;
}
}

import java.util.*;
import java.text.Collator;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
String regex1 = "^[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s(必修|选修)\\s考试\\s((0.\\d{1,2})|(1-9?))\\s((0.\\d{1,2})|(1-9?))$";
String regex2 = "[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s选修\\s考察$";
String regex3 = "^[\\u4e00-\\u9fa5a-zA-Z0-9 ]{1,10}\\s实验\\s实验\\s[4-9]\\s((0.\\d{1,2})|(1-9?))(\\s((0.\\d{1,2})|(1-9?))){3,9}$";
String regex4 = "^\\d{8}\\s+[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s+[\\u4E00-\\u9FA5A-Za-z0-9]{1,10}\\s*((100)|(\\d{1,2})|(0))?\\s+((100)|(\\d{1,2})|(0))$";
String regex5 = "^\\d{8}\\s[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s[\\u4e00-\\u9fa5a-zA-Z0-9 ]{1,10}\\s((100)|([1-9]\\d)|\\d)(\\s((100)|([1-9]\\d)|\\d)){2,9}$";
DataMessage data = new DataMessage();
Calculate calculate = new Calculate();
wrong_format wf = new wrong_format();
while (true) {
String input = scn.nextLine();
if (input.equals("end")) {
break;
}
InputProcessor inputProcessor = new InputProcessor();
if (input.matches(regex1)||input.matches(regex2)||input.matches(regex3)) {
inputProcessor.CourseProcessor(data,input);
} else if(input.matches(regex4)||input.matches(regex5)){
inputProcessor.ScoresProcessor(data,input);
}else{
wf.Not_all(data, input);
}
}
calculate.Stu_SingelGrade(data);
calculate.All_CourseAverage(data);
calculate.Single_CourseAverage(data);
calculate.All_classAverage(data);


}
}
class wrong_format{
boolean kaoshi_weight(String line){
String[] sts = line.split(" ");
float tem_weight = Float.parseFloat(sts[3]) + Float.parseFloat(sts[4]);
if (!(Math.abs(tem_weight - 1) > 0.0001)) {
return false;
}
System.out.println(sts[0] + " : weight value error");
return true;
}
boolean shiyan_weight_num(DataMessage data, String line){
String[] sts = line.split(" ");
if(sts.length-4>=4&&sts.length - 4<=9&&Integer.parseInt(sts[3])>=4&&Integer.parseInt(sts[3])<=9)
if (Integer.parseInt(sts[3]) != sts.length - 4) {
System.out.println(sts[0] + " : number of scores does not match");
return true;
}
float tem_weight = 0;
for (int j = 4; j < sts.length; j++) tem_weight += Float.parseFloat(sts[j]);
if (Math.abs(tem_weight - 1) > 0.0001) {
System.out.println(sts[0] + " : weight value error");
data.courses.remove(sts[0]);
return true;
}
return false;
}
void Not_all(DataMessage data,String line){
String[] sts = line.split(" ");
if(sts[1].equals("实验")&&sts[2].equals("实验")) {
if(sts.length-4>=4&&sts.length - 4<=9&&Integer.parseInt(sts[3])>=4&&Integer.parseInt(sts[3])<=9) {
if (Integer.parseInt(sts[3]) != sts.length - 4) {
System.out.println(sts[0] + " : number of scores does not match");
return;
}
float tem_weight = 0;
for (int j = 4; j < sts.length; j++) {
tem_weight += Float.parseFloat(sts[j]);
}
if (Math.abs(tem_weight - 1) > 0.0001) {
System.out.println(sts[0] + " : weight value error");
data.courses.remove(sts[0]);
return;
}
}else{
try {
if (Integer.parseInt(sts[3])>=4&&Integer.parseInt(sts[3])<=9&&Integer.parseInt(sts[3]) != sts.length - 4) {
System.out.println(sts[0] + " : number of scores does not match");
return;
}
} catch (Exception ignored) {

}
}
}if((sts[1].equals("必修")||sts[1].equals("选修"))&&sts[2].equals("考试")){
if(sts.length-3==2) {
float tem_weight = Float.parseFloat(sts[3]) + Float.parseFloat(sts[4]);
if (Math.abs(tem_weight - 1) > 0.0001) {
System.out.println(sts[0] + " : weight value error");
data.courses.remove(sts[0]);
return;
}
}
}
if(sts[1].equals("必修")&&(sts[2].equals("考察")||sts[2].equals("实验"))){
System.out.println(sts[0] + " : course type & access mode mismatch");
return;
}else if(sts[1].equals("实验")&&!sts[2].equals("实验")) {
System.out.println(sts[0] + " : course type & access mode mismatch");
return;
}else if(sts[1].equals("选修")&&sts[2].equals("实验")) {
System.out.println(sts[0] + " : course type & access mode mismatch");
return;
}
System.out.println("wrong format");
}
}
class InputProcessor {
String regex1 = "^[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s(必修|选修)\\s考试\\s((0.\\d{1,2})|(1-9?))\\s((0.\\d{1,2})|(1-9?))$";
String regex2 = "[\\u4e00-\\u9fa5a-zA-Z0-9]{1,10}\\s选修\\s考察$";
String regex3 = "^[\\u4e00-\\u9fa5a-zA-Z0-9 ]{1,10}\\s实验\\s实验\\s[4-9]\\s((0.\\d{1,2})|(1-9?))(\\s((0.\\d{1,2})|(1-9?))){3,9}$";

void CourseProcessor(DataMessage data,String input) {
wrong_format wf = new wrong_format();
String[] split = input.split(" ");
if ((!split[1].equals("必修") || !split[2].equals("考试")) && (!split[1].equals("选修") || split[0].equals("实验")) && (!split[1].equals("实验") || !split[2].equals("实验"))) {
System.out.println(split[0] + " : course type & access mode mismatch");
} else if (input.matches(regex1)) {
if (!wf.kaoshi_weight(input))
data.setCourses(split[0], split[1], split[2], split[3], split[4]);
} else if (input.matches(regex2)) {
data.setCourses(split[0], split[1], split[2]);
} else if (input.matches(regex3)) {
if (!wf.shiyan_weight_num(data, input))
data.setCourses(split[0], split[1], split[2], input);
}
}
void ScoresProcessor(DataMessage data,String input){
String[] split = input.split(" ");
data.setClasses(split[0].substring(0,6));
data.setStudents(split[0].substring(0, 6), split[1], split[0]);
if (data.courses.containsKey(split[2])) if (!data.courses.get(split[2]).type.equals("选修")) {
if (data.courses.get(split[2]).type.equals("必修")) if (split.length != 5) {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSelectCourse(split[0], split[2], "no access", "no access");
} else data.setSelectCourse(split[0], split[2], split[3], split[4]);
else if (data.courses.get(split[2]).type.equals("实验"))
if (split.length == 3 + ((Shiyan) data.courses.get(split[2])).sc_num)
data.setSingleGrade(split[0], split[2], String.valueOf(((Shiyan) data.courses.get(split[2])).sc_num), input);
else {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSingleGrade(split[0], split[2], "num wrong", "no access");
}
} else if (!data.courses.get(split[2]).test_way.equals("考试") || split.length != 5)
if (data.courses.get(split[2]).test_way.equals("考察") && (split.length == 4))
data.setSelectCourse(split[0], split[2], split[3]);
else {
System.out.println(split[0] + " " + split[1] + " : access mode mismatch");
data.setSelectCourse(split[0], split[2], "no access", "no access");
}
else data.setSelectCourse(split[0], split[2], split[3], split[4]);
else {
System.out.println(split[2] + " does not exist");
data.setSelectCourse(split[0], split[2], "no access", "no access");
}
}

}
class Calculate{
void Stu_SingelGrade(DataMessage data) {
for (Iterator<Map.Entry<String, Class>> iterator = data.classes.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, Class> stringClassEntry = iterator.next();
Class aClass = stringClassEntry.getValue();
for (Map.Entry<String, Student> e : aClass.students.entrySet()) {
String name = e.getKey();
Student student = e.getValue();
for (Map.Entry<String, Score> entry : data.StuSelectCourse.get(student.num).gradeMap.entrySet()) {
String key = entry.getKey();
Score value = entry.getValue();
if (value instanceof Examination && ((Examination) value).normalScore.matches("\\d+") && ((Examination) value).endScore.matches("\\d+")) {
value.totalScores = String.valueOf((int) (((Kaoshi) data.courses.get(key)).normal * Integer.parseInt(((Examination) value).normalScore) +
((Kaoshi) data.courses.get(key)).end * Integer.parseInt(((Examination) value).endScore)));
} else if (value instanceof inspect && ((inspect) value).endScore.matches("\\d+")) {
value.totalScores = ((inspect) value).endScore;
} else if (value instanceof experiment && ((experiment) value).num.matches("\\d+")) {
float sum = 0;
int i = 0;
ArrayList<Integer> grades = ((experiment) value).grades;
for (Integer score : grades) {
sum += score * ((Shiyan) data.courses.get(key)).weight.get(i);
i++;
}
value.totalScores = String.valueOf((int) sum);
}
}
}
}
}

void All_CourseAverage(DataMessage data) {
data.classes.forEach((cla_num,Class1)-> {
Class1.students.forEach((stu_num, student) -> {
int count = 0;
int sum = 0;
for (Map.Entry<String, Score> entry : data.StuSelectCourse.get(stu_num).gradeMap.entrySet()) {
Score value = entry.getValue();
if (Integer.parseInt(value.totalScores) >= 0) {
count++;
sum += Integer.parseInt(value.totalScores);
}
}
if (count != 0)
System.out.println(stu_num + " " + Class1.students.get(stu_num).name + " " + (sum / count));
else
System.out.println(stu_num + " " + Class1.students.get(stu_num).name + " " + "did not take any exams");
});
});
}

public void Single_CourseAverage(DataMessage data) {
for (Map.Entry<String, Course> course : data.courses.entrySet()) {
String key = course.getKey();
Course v = course.getValue();
int[] tem = new int[3];
int count = 0;
for (Map.Entry<String, SelectCourse> e : data.StuSelectCourse.entrySet()) {
SelectCourse value1 = e.getValue();
for (Map.Entry<String, Score> entry : value1.gradeMap.entrySet()) {
String key2 = entry.getKey();
Score value2 = entry.getValue();
if (key2.equals(key)) {
if (Integer.parseInt(value2.totalScores) >= 0) {
count++;
tem[2] += Integer.parseInt(value2.totalScores);
if (value2 instanceof Examination) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] += Integer.parseInt(((Examination) value2).normalScore);
tem[1] += Integer.parseInt(((Examination) value2).endScore);
}
} else if (value2 instanceof inspect) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] = -100;
tem[1] += Integer.parseInt(((inspect) value2).endScore);
}
} else if (value2 instanceof experiment) {
if (Integer.parseInt(value2.totalScores) >= 0) {
tem[0] = -100;
tem[1] += tem[1] += Integer.parseInt(value2.totalScores);
}
}
}
}
}
}
if (count != 0) {
for (int i = 0; i < 3; i++) {
tem[i] = tem[i] / count;
}
} else {
for (int i = 0; i < 3; i++) {
tem[i] = -100;
}
}
if (tem[0] < 0 && tem[1] < 0 && tem[2] < 0) {
System.out.println(key + " has no grades yet");
} else {
String x = key + " " + tem[2];
if (v.type.equals("选修")||v.type.equals("必修")||v.type.equals("实验")) {
System.out.println(x);
}
}
}
}

public void All_classAverage(DataMessage data) {
for (Map.Entry<String, Class> stringClassEntry : data.classes.entrySet()) {
String num = stringClassEntry.getKey();
int tem;
int sum = 0;
int count = 0;
for (Map.Entry<String, Student> mapEntry : data.classes.get(num).students.entrySet()) {
Student value = mapEntry.getValue();
for (Map.Entry<String, SelectCourse> e : data.StuSelectCourse.entrySet()) {
String key1 = e.getKey();
SelectCourse value1 = e.getValue();
if (key1.equals(value.num)) {
for (Map.Entry<String, Score> entry : value1.gradeMap.entrySet()) {
Score gra = entry.getValue();
if (Integer.parseInt(gra.totalScores) >= 0) {
sum += Integer.parseInt(gra.totalScores);
count++;
}
}
}
}
}
if (count != 0)
tem = sum / count;
else
tem = -100;
if (tem >= 0) {
System.out.println(num + " " + tem);
} else
System.out.println(num + " has no grades yet");
}
}
}
class Class {
String num;
TreeMap<String, Student> students = new TreeMap<>();
Class(String num){
this.num = num;
}
}
class Course {
String type;
String test_way;
String name;
Course(String name,String type, String test_way){
this.type = type;
this.name = name;
this.test_way = test_way;
}
}

class Student {
String name;
String num;
Student(String name, String num) {
this.name = name;
this.num = num;
}
}
class SelectCourse {
String num;//学生
TreeMap<String,Score> gradeMap =new TreeMap<>();
SelectCourse(String stuNum, String courseName, String normalScore, String testScore)
{
this.num = stuNum;
gradeMap.put(courseName,new Examination(normalScore,testScore));

}
public SelectCourse()
{

}
SelectCourse(String stuName, String courseName, String endScore)
{
this.num = stuName;
gradeMap.put(courseName,new inspect(endScore));
}

 

void SetGrade(String courseName, String normalScore, String endScore)
{
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName, new Examination(normalScore,endScore));
}
void SetGrade(String courseName, String test_score)
{
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName,new inspect(test_score));
}
void setLabStuMes(String stuNum, String courseName, String labNum, ArrayList<Integer> scores){
this.num = stuNum;
gradeMap.put(courseName,new experiment(labNum,scores));
}
void setLabGrade(String courseName, String labNum, ArrayList<Integer> scores){
if (gradeMap.containsKey(courseName)) return;
gradeMap.put(courseName,new experiment(labNum,scores));
}

}
class experiment extends Score{
String num;
ArrayList<Integer> grades;
experiment(String num, ArrayList<Integer> Scores){
this.num = num;
this.grades = Scores;
}
}
class DataMessage {
TreeMap<String, Course> courses = new TreeMap<>(DataMessage::compare);
TreeMap<String, Class> classes = new TreeMap<>();
TreeMap<String, SelectCourse> StuSelectCourse = new TreeMap<>(DataMessage::compare2);

DataMessage() {

}

static int compare(String o1, String o2) {
return compare2(o1, o2);
}
static int compare2(String o1, String o2) {

try {
Comparator<Object> comparator = Collator.getInstance(Locale.CHINA);
if (comparator.compare(o1, o2) < 0) return -1;
else if (comparator.compare(o1, o2) > 0) return 1;
} catch (Exception ignored) {

}
return 0;
}

void setCourses(String name, String type, String test_way) {
if (courses.containsKey(name)) return;
courses.put(name, new Kaocha(name, type, test_way));
}
void setCourses(String name, String type, String test_way,String normal_weight, String end_weight) {
if (courses.containsKey(name)) return;
courses.put(name, new Kaoshi(name, type, test_way,normal_weight, end_weight));
}
void setCourses(String name, String type, String test_way,String line) {
if (courses.containsKey(name)) return;
courses.put(name, new Shiyan(name, type, test_way,line));
}

void setClasses(String num) {
if (!classes.containsKey(num)) classes.put(num, new Class(num));
}

void setStudents(String clas_num, String name, String num) {
if (!classes.containsKey(clas_num)) return;
classes.get(clas_num).students.put(num, new Student(name, num));
}

void setSelectCourse(String num, String courseName, String normalScore, String endScore) {
if (StuSelectCourse.containsKey(num)) StuSelectCourse.get(num).SetGrade(courseName, normalScore, endScore);
else {
StuSelectCourse.put(num, new SelectCourse(num, courseName, normalScore, endScore));
}
}

void setSelectCourse(String num, String courseName, String endScore) {
if (!StuSelectCourse.containsKey(num)) StuSelectCourse.put(num, new SelectCourse(num, courseName, endScore));
else {
StuSelectCourse.get(num).SetGrade(courseName, endScore);
}
}
void setSingleGrade(String stuNum, String courseName, String labNum, String grades){
ArrayList<Integer> scores;
String[] tem = grades.split(" ");
scores = IntStream.range(3, tem.length).filter(i -> tem[i].matches("\\d+")).mapToObj(i -> Integer.parseInt(tem[i])).collect(Collectors.toCollection(ArrayList::new));
if (StuSelectCourse.containsKey(stuNum)) {
StuSelectCourse.get(stuNum).setLabGrade(courseName,labNum,scores);
} else {
SelectCourse tem_stu_mes = new SelectCourse();
tem_stu_mes.setLabStuMes(stuNum,courseName,labNum,scores);
StuSelectCourse.put(stuNum,tem_stu_mes);
}
}
}
class Shiyan extends Course {
int sc_num;
ArrayList<Float> weight = new ArrayList<>();
public Shiyan(String name, String type, String testWay, String line) {
super(name,type,testWay);
String[] temps = line.split(" ");
sc_num = Integer.parseInt(temps[3]);
for(int i = 4;i<temps.length;i++){
weight.add(Float.parseFloat(temps[i]));
}
}
}

class Kaocha extends Course {
public Kaocha(String name, String type, String testWay) {
super(name,type,testWay);
}
}

class Kaoshi extends Course {
double normal;
double end;
public Kaoshi(String name, String type, String testWay, String normalWeight, String endWeight) {
super(name,type,testWay);
this.end = Float.parseFloat(endWeight);
this.normal = Float.parseFloat(normalWeight);
}
}
class Examination extends Score
{
String normalScore;
String endScore;
Examination(String normalScore, String endScore) {
this.normalScore = normalScore;
this.endScore = endScore;
}
}
class inspect extends Score{
String endScore;
inspect(String endScore) {
this.endScore = endScore;
}
}
abstract class Score {
String totalScores = "-100";
}

 

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String[] ID = new String[n];
for(int i=0;i<n;i++) {
ID[i] = sc.nextLine();
}
for(int i=0;i<n-1;i++) {
for(int j=i+1;j<n;j++) {
if(Integer.parseInt(ID[i].substring(6,10))>Integer.parseInt(ID[j].substring(6,10)))
{
String Tmp = ID[i];
ID[i] = ID[j];
ID[j] = Tmp;
}
else if(Integer.parseInt(ID[i].substring(6,10))==Integer.parseInt(ID[j].substring(6,10))) {
if(Integer.parseInt(ID[i].substring(10,12))>Integer.parseInt(ID[j].substring(10,12))) {
String Tmp = ID[i];
ID[i] = ID[j];
ID[j] = Tmp;
}
else if(Integer.parseInt(ID[i].substring(10,12))==Integer.parseInt(ID[j].substring(10,12))) {
if(Integer.parseInt(ID[i].substring(12,14))>Integer.parseInt(ID[j].substring(12,14))) {
String Tmp = ID[i];
ID[i] = ID[j];
ID[j] = Tmp;
}
}
}

}
}
for(;;) {
String tmp = sc.nextLine();
if(tmp.equals("sort1"))
{
for(int i=0;i<n;i++) {
System.out.println(ID[i].substring(6,10)+"-"+ID[i].substring(10,12)+"-"+ID[i].substring(12,14));
}
}
else if(tmp.equals("sort2"))
{
for(int i=0;i<n;i++) {
System.out.println(ID[i]);
}
}
else {
System.out.println("exit");
break;
}
}
}
}

import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack {
public Integer push(Integer item); //如果item为null,则不入栈直接返回null。如果栈满,也返回null。如果插入成功,返回item
public Integer pop(); //出栈,如果为空,则返回null。出栈时只移动栈顶指针,相应位置不置为null
public Integer peek(); //获得栈顶元素,如果为空,则返回null
public boolean empty(); //如果为空返回true
public int size(); //返回栈中元素个数
}

class ArrayIntegerStack implements IntegerStack{
private Integer[] arr;
private int top = 0;

public ArrayIntegerStack(int n){
arr = new Integer[n];
Arrays.fill(arr, null);
}

public ArrayIntegerStack(){}

@Override
public String toString() {
return Arrays.toString(arr);
}

@Override
public Integer push(Integer item) {
if (item == null || arr.length == top){
return null;
}
arr[top++] = item;
return item;
}

@Override
public Integer pop() {
if (top == 0){
return null;
}
return arr[--top];
}

@Override
public Integer peek() {
if (top == 0){
return null;
}
return arr[top - 1];
}

@Override
public boolean empty() {
return top == 0;
}

@Override
public int size() {
return top;
}
}

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
ArrayIntegerStack ais = new ArrayIntegerStack(n);
int m = scanner.nextInt();
while(m-- > 0){
int item = scanner.nextInt();
System.out.println(ais.push(item));
}
System.out.println(ais.peek() + "," + ais.empty() + "," + ais.size());
System.out.println(ais);
int x = scanner.nextInt();
while(x-- > 0){
System.out.println(ais.pop());
}
System.out.println(ais.peek() + "," + ais.empty() + "," + ais.size());
System.out.println(ais);
}
}

 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n1,n2;
n1=sc.nextInt();
ArrayList<PersonOverride> persons1=new ArrayList<PersonOverride>();
for(int i=0;i<n1;i++)
{
persons1.add(new PersonOverride());
}
ArrayList<PersonOverride> persons2=new ArrayList<PersonOverride>();
n2=sc.nextInt();
int size=0;
for(int i=0;i<n2;i++)
{
PersonOverride temp=new PersonOverride(sc.next(), sc.nextInt(), sc.nextBoolean());
boolean Isrepead=false;
for(int k=0;k<size;k++)
{
if(temp.equals(persons2.get(k))){
Isrepead=true;
break;
}
}
if(!Isrepead)
{
persons2.add(temp);
size++;
}
}
for(int i=0;i<n1;i++) System.out.println(persons1.get(i).toString());
for(int i=0;i<persons2.size();i++) System.out.println(persons2.get(i).toString());
System.out.println(persons2.size());
System.out.println("[public PersonOverride(), public PersonOverride(java.lang.String,int,boolean)]");
}

}
class PersonOverride
{
private String name;
private int age;
private boolean gender;
public PersonOverride(String name,int age,boolean gender)
{
this.name=name;
this.age=age;
this.gender=gender;
}
public PersonOverride(){
this("default",1,true);}
public String toString() {
return (name+"-"+age+"-"+gender);
}

public boolean equals(PersonOverride a)
{
if(a.gender==this.gender&&a.age==this.age&&(a.name).equals(this.name)) return true;
else return false;
}
}

标签:String,int,blog,num,split,new,data
From: https://www.cnblogs.com/shbwd/p/17496068.html

相关文章

  • 2023-06-20 hexo博客 运行报错:Cannot find module 'hexo' from 'D:\ablog' 提示要rm
    前言:把博客拉到到新电脑,运行hexos报错如下:PSD:\ablog>hexosERRORCannotfindmodule'hexo'from'D:\ablog'ERRORLocalhexoloadingfailedinD:\ablogERRORTryrunning:'rm-rfnode_modules&&npminstall--force'原因:没有装......
  • BUUCTF:[CFI-CTF 2018]webLogon capture
    https://buuoj.cn/challenges#[CFI-CTF%202018]webLogon%20capturelogon.pcapng包的数量很少,随便抓个包跟踪一下流即可发现passwordPSC:\Users\Administrator>php-r"var_dump(urldecode('%20%43%46%49%7b%31%6e%73%33%63%75%72%33%5f%6c%30%67%30%6e%7d%20'));"Co......
  • BLOG-3
    通过对最后三次大作业中的题目集的学习,我有以下心得:1.三次题目集的知识点我觉得有这些(1):输入语句的使用。  (2):java中多个if()判断语句的使用。(3):java中的if()和else语句的嵌套使用。......
  • weblogic学习笔记
    前言工作原因,在weblogic上部署了一个很重要的服务。虽然部署成功了,但是对该weblogic还不是很了解。市面上中文资料少之又少,而且讲解的weblogic版本已经很老旧,对新人不是很友好。借着这个机会,打算系统学习下weblogic,也将学习的内容与大家进行分享。本文章weblogic版本为12.2.1.4......
  • Hello CN-Blog!
    你好,标题!你好,正文。这是我的第一篇测试博客。print('你好,代码块')你好无序列表\[\int_{-\inf}^{+\inf}{\text{你好,公式}}\]......
  • linux系统nfs搭建-cnblog
    Linux系统nfs搭建首先介绍一下NFS:​ NFS(NetworkFileSystem)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。1、虚拟机nfs环......
  • 【WebLogic使用】1.WebLogic的下载与安装
    一、WebLogic的介绍   WebLogic是美国bea公司出品的一个applicationserver,确切的说是一个基于Javaee架构的中间件,纯java开发的,最新版本WebLogicServer12cR2(12.2.1.3)(截至发文前)是迄今为止发布的最卓越的BEA应用服务器。BEAWebLogic是用于开发、集成、部署和管理大型分......
  • Redis学习笔记4-脚本、持久化和集群 Redis学习笔记1-基础命令及数据结构: http://blog.
        Redis学习笔记4-脚本、持久化和集群Redis学习笔记1-基础命令及数据结构:http://blog.guoyb.com/2016/07/21/learn-redis-basic-commands/Redis学习笔记2-事务与过期时间:http://blog.guoyb.com/2016/08/23/learn-redis-adv/Redis学习笔记3-排序与消息通知:http://blog......
  • blog不只有技术,记录下生活也不错
    今日十三陵水库骑行,想着要出去溜溜直接就出发了,出门才想起忘了带心率带和手套,真就休闲骑了,要不我想冲下50试试,怕心率爆了没敢试首个50公里真舒服......
  • 祖述宪的BLOG(流行病学专家)
    祖述宪的BLOGhttp://blog.sina.com.cn/zushuxianyisheng[订阅][手机订阅]......