ZZULIOJ 1186: 删除记录(结构体专题),Java

ZZULIOJ 1186: 删除记录(结构体专题),Java

题目描述

有一学生成绩表,包括学号、姓名、3门课程成绩。请实现如下删除功能:输入一个学生的学号,删除该学生的所有信息。

输入

首先输入一个整数n(1<=n<=100),表示学生人数;
然后输入n行,每行包含一个学生的信息:学号(12位)、姓名(不含空格且不超过20位),以及3个整数,表示3门课成绩,数据之间用空格隔开。
最后一行输入一个学号num。

输出

若要删除的学号不存在,则输出error!;否则,输出删除该学生后的所有记录。

样例输入 Copy
3
541207010188 Zhangling 78 95 55
541207010189 Wangli 87 99 88
541207010190 Fangfang 68 76 75
541207010188
样例输出 Copy
541207010189 Wangli 87 99 88
541207010190 Fangfang 68 76 75
import java.util.ArrayList;
import java.util.Scanner;
 
class Student {
    String id;
    String name;
    int score1;
    int score2;
    int score3;
 
    public Student(String id, String name, int score1, int score2, int score3) {
        this.id = id;
        this.name = name;
        this.score1 = score1;
        this.score2 = score2;
        this.score3 = score3;
    }
}
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String id = sc.next();
            String name = sc.next();
            int score1 = sc.nextInt();
            int score2 = sc.nextInt();
            int score3 = sc.nextInt();
            students.add(new Student(id, name, score1, score2, score3));
        }
        String deleteId = sc.next();
        boolean studentDeleted = students.removeIf(student -> student.id.equals(deleteId));
        if (!studentDeleted) {
            System.out.println("error!");
        } else {
            for (Student student : students) {
                System.out.println(student.id + " " + student.name + " " + student.score1 + " " + student.score2 + " " + student.score3);
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wa_Automata

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值