-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinerTask.java
More file actions
44 lines (35 loc) · 1.12 KB
/
MinerTask.java
File metadata and controls
44 lines (35 loc) · 1.12 KB
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
38
39
40
41
42
43
44
package MinerTask;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MinerTask {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int rowCounter = 1;
String resource = null;
Map<String,Integer> map = new HashMap<>();
while(true){
String input = scan.nextLine();
if(input.equals("stop"))
break;
//if odd
if(rowCounter % 2 == 1){
boolean isAvailable = map.containsKey(input);
if(!isAvailable){
map.put(input,0);
}
}
//if even
else{
int currentQuantity = map.get(resource);
int totalQuantity = currentQuantity + Integer.parseInt(input);
map.put(resource,totalQuantity);
}
rowCounter++;
resource = input;
}
for (Map.Entry<String, Integer> s : map.entrySet()) {
System.out.printf("%s -> %d%n",s.getKey(),s.getValue());
}
}
}