
import java.util.*; |
public class Main{ |
public static void main(String[] args ) { |
Scanner scan = new Scanner(System.in); |
int num, no, score, i, j; |
String name, op; |
|
num = scan.nextInt(); |
Map<Integer, Student> map = new HashMap<Integer, Student>(); |
Student s; |
for(i = 0; i < num; i++) { |
no = scan.nextInt(); |
name = scan.next(); |
score = scan.nextInt(); |
s = new Student(no, name, score); |
map.put(no, s); |
} |
num = scan.nextInt(); |
|
for(j = 0; j < num; j++) { |
op = scan.next(); |
if(op.equals("add")){ |
no = scan.nextInt(); |
name = scan.next(); |
score = scan.nextInt(); |
s = new Student(no, name, score); |
map.put(no, s); |
} |
else if(op.equals("delete")) { |
no = scan.nextInt(); |
map.remove(no); |
} |
else if(op.equals("set")) { |
no = scan.nextInt(); |
score = scan.nextInt(); |
map.get(no).setScore(score); |
} |
} |
Iterator<Map.Entry<Integer, Student>> iter = map.entrySet().iterator(); |
while(iter.hasNext()) { |
Map.Entry<Integer, Student> entry = iter.next(); |
System.out.println(entry.getValue()); |
} |
scan.close(); |
} |
} |
class Student{ |
int no; |
String name; |
int score; |
public Student(int _no, String _name, int _score) { |
no = _no; |
name = _name; |
score = _score; |
} |
public int getNo() { |
return no; |
} |
public String getName() { |
return name; |
} |
public int getScore() { |
return score; |
} |
public void setScore(int sc) { |
score = sc; |
} |
public String toString() { |
return "no:" +no +" name:" +name +" score:" +score; |
} |
public boolean equals(Student s) { |
if(this.no==s.getNo() && this.name.equals(s.getName()) && this.score==s.getScore()) |
return true; |
else |
return false; |
} |
public int hashcode() { |
int result = 17; |
result = 31*result + no; |
return result; |
} |
} |




中级程序员
by: 买了否冷 发表于:2018-12-05 16:25:58 顶(1) | 踩(1) 回复
if判断条件会发生空指针异常吧
回复评论