package MAIN;
import Book.*;
import java.util.*;
public class slove {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String name; int val, num;
HashMap<Book, Integer> str = new HashMap<Book, Integer>();
for(int i = 0; i < n; ++i) {
name = in.next();
val = in.nextInt();
num = in.nextInt();
Integer second = Integer.valueOf(val) * Integer.valueOf(num);
Book first = new Book(name, val, num);
str.put(first, second);
}
int ans = getSum(str);
System.out.println(ans);
}
public static int getSum(HashMap rhs) {
int sum = 0;
Iterator it = rhs.entrySet().iterator();
while(it.hasNext()) {
Map.Entry<Book, Integer> entry = (Map.Entry<Book, Integer>)it.next();
Integer value = entry.getValue();
sum += (int)value;
}
return sum;
}
}
循环遍历HashMap的较快方法
最新推荐文章于 2025-02-19 21:12:20 发布
本文深入探讨了Java编程中如何利用HashMap和Book类进行数据管理和操作,通过实例展示了如何实现数据的存储、计算和输出,提供了一个实用的编程解决方案。

5372

被折叠的 条评论
为什么被折叠?



