-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMinerTask.java
37 lines (32 loc) · 1.11 KB
/
AMinerTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Exercises;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class AMinerTask {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
int count = 1;
String resource = "";
int quantity = 0;
Map<String,Integer> map = new LinkedHashMap<>();
while(!input.equals("stop")){
if(count % 2 != 0){
resource = input;
}else {
int conversion = Integer.parseInt(input);
if (map.containsKey(resource)) {
quantity = map.get(resource);
map.put(resource, conversion + quantity);
} else {
map.put(resource, conversion);
}
}
count++;
input = scan.nextLine();
}
for(Map.Entry<String, Integer> pair : map.entrySet()){
System.out.println(String.format("%s -> %d",pair.getKey(),pair.getValue()));
}
}
}