-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKatoPaternity.java
63 lines (60 loc) · 1.88 KB
/
KatoPaternity.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
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
import java.util.Set;
public class KatoPaternity {
/**
* Определение родительского кода КАТО
* @param val код КАТО
* @param codeSet Набор всех КАТО
* @return родительский код
*/
static int getParent(int val, Set<Integer> codeSet){
int tmp;
if(val % 10000000 == 0) {
return -1;
}
if (val % 100000 == 0) {
if(codeSet.contains(tmp = val - val % 10000000)){
return tmp;
}
} else if (val % 10000 == 0) {
if(codeSet.contains(tmp = val - val % 100000)){
return tmp;
}
if(codeSet.contains(tmp = val - val % 1000000)){
return tmp;
}
if(codeSet.contains(tmp = val - val % 10000000)){
return tmp;
}
} else if (val % 1000 == 0) {
if(codeSet.contains(tmp = val - val % 100000)){
return tmp;
}
} else if (val % 100 == 0) {
if(codeSet.contains(tmp = val - val % 1000)){
return tmp;
}
if(codeSet.contains(tmp = val - val % 100000)){
return tmp;
}
if(codeSet.contains(tmp = val - val % 1000000)){
return tmp;
}
} else if(val % 100 > 80) {
if(codeSet.contains(tmp = val - val % 10)){
return tmp;
}
} else if(val % 100 == 80) {
if(codeSet.contains(tmp = val - val % 1000)){
return tmp;
}
} else if(val % 100 > 0) {
if(codeSet.contains(tmp = val - val % 100)){
return tmp;
}
if(codeSet.contains(tmp = val - val % 1000)){
return tmp;
}
}
return -1;
}
}