-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExcel.java
More file actions
67 lines (60 loc) · 1.76 KB
/
Copy pathExcel.java
File metadata and controls
67 lines (60 loc) · 1.76 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.HashMap;
import java.util.Map;
public class Excel
{
int[][] sheet;
Map<String, String[]> Sumfunctions;
public Excel(int H, char W)
{
int n = W - 'A' + 1;
sheet = new int[H][n];
Sumfunctions = new HashMap<>();
}
public void set(int r, char c, int v)
{
Sumfunctions.remove("" + r + c);
sheet[r - 1][c - 'A'] = v;
}
public int get(int r, char c)
{
return Sumfunctions.get("" + r + c) == null ? sheet[r - 1][c - 'A'] : sum(r, c, Sumfunctions.get("" + r + c));
}
public int sum(int r, char c, String[] strs)
{
Sumfunctions.put("" + r + c, strs);
int sum = 0;
for (String str : strs)
{
if (str.contains(":"))
{
String[] boundaries = str.split(":");
String left = boundaries[0];
String right = boundaries[1];
int rowStart = 0, rowEnd = 0;
int start = 1;
while (start < left.length())
{
rowStart = rowStart * 10 + (left.charAt(start++) - '0');
}
start = 1;
while (start < right.length())
{
rowEnd = rowEnd * 10 + (right.charAt(start++) - '0');
}
for (char i = left.charAt(0); i <= right.charAt(0); i++)
{
for (int j = rowStart; j <= rowEnd; j++)
{
sum += get(j, i);
}
}
}
else
{
sum += get(str.charAt(1) - '0', str.charAt(0));
}
}
sheet[r - 1][c - 'A'] = sum;
return sum;
}
}