Skip to content

Commit 8e75441

Browse files
committed
做题
1 parent 382af98 commit 8e75441

11 files changed

Lines changed: 548 additions & 14 deletions

File tree

activitiInside.bpmn

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_028qoy6" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.14.0">
3+
<bpmn:process id="Process_1" name="测试流程1" isExecutable="true">
4+
<bpmn:laneSet />
5+
<bpmn:startEvent id="StartEvent_1" name="开始">
6+
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
7+
</bpmn:startEvent>
8+
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1" />
9+
<bpmn:task id="Task_1" name="第一个任务">
10+
<bpmn:extensionElements>
11+
<camunda:properties>
12+
<camunda:property name="name" value="task1" />
13+
</camunda:properties>
14+
</bpmn:extensionElements>
15+
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
16+
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
17+
</bpmn:task>
18+
<bpmn:sequenceFlow id="SequenceFlow_2" name="条件判断" sourceRef="Task_1" targetRef="Task_2">
19+
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${name=="1"}</bpmn:conditionExpression>
20+
</bpmn:sequenceFlow>
21+
<bpmn:endEvent id="EndEvent_1r5n15x" name="结束">
22+
<bpmn:incoming>SequenceFlow_3</bpmn:incoming>
23+
</bpmn:endEvent>
24+
<bpmn:sequenceFlow id="SequenceFlow_3" sourceRef="Task_2" targetRef="EndEvent_1r5n15x" />
25+
<bpmn:task id="Task_2" name="第二个任务">
26+
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
27+
<bpmn:outgoing>SequenceFlow_3</bpmn:outgoing>
28+
</bpmn:task>
29+
</bpmn:process>
30+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
31+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
32+
<bpmndi:BPMNEdge id="SequenceFlow_0qv40ek_di" bpmnElement="SequenceFlow_1">
33+
<di:waypoint x="209" y="120" />
34+
<di:waypoint x="273" y="120" />
35+
<bpmndi:BPMNLabel>
36+
<dc:Bounds x="241" y="99" width="0" height="12" />
37+
</bpmndi:BPMNLabel>
38+
</bpmndi:BPMNEdge>
39+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
40+
<dc:Bounds x="173" y="102" width="36" height="36" />
41+
<bpmndi:BPMNLabel>
42+
<dc:Bounds x="180" y="138" width="22" height="12" />
43+
</bpmndi:BPMNLabel>
44+
</bpmndi:BPMNShape>
45+
<bpmndi:BPMNShape id="Task_1og1a32_di" bpmnElement="Task_1">
46+
<dc:Bounds x="273" y="80" width="100" height="80" />
47+
</bpmndi:BPMNShape>
48+
<bpmndi:BPMNEdge id="SequenceFlow_0gmrzu7_di" bpmnElement="SequenceFlow_2">
49+
<di:waypoint x="373" y="120" />
50+
<di:waypoint x="451" y="120" />
51+
<bpmndi:BPMNLabel>
52+
<dc:Bounds x="390" y="99" width="44" height="12" />
53+
</bpmndi:BPMNLabel>
54+
</bpmndi:BPMNEdge>
55+
<bpmndi:BPMNShape id="EndEvent_1r5n15x_di" bpmnElement="EndEvent_1r5n15x">
56+
<dc:Bounds x="628" y="102" width="36" height="36" />
57+
<bpmndi:BPMNLabel>
58+
<dc:Bounds x="635" y="142" width="22" height="12" />
59+
</bpmndi:BPMNLabel>
60+
</bpmndi:BPMNShape>
61+
<bpmndi:BPMNEdge id="SequenceFlow_1d7jgs8_di" bpmnElement="SequenceFlow_3">
62+
<di:waypoint x="551" y="120" />
63+
<di:waypoint x="628" y="120" />
64+
<bpmndi:BPMNLabel>
65+
<dc:Bounds x="544.5" y="99" width="90" height="12" />
66+
</bpmndi:BPMNLabel>
67+
</bpmndi:BPMNEdge>
68+
<bpmndi:BPMNShape id="Task_0k6x62v_di" bpmnElement="Task_2">
69+
<dc:Bounds x="451" y="80" width="100" height="80" />
70+
</bpmndi:BPMNShape>
71+
</bpmndi:BPMNPlane>
72+
</bpmndi:BPMNDiagram>
73+
</bpmn:definitions>

src/main/java/com/code/repository/study/activiti/ActivitiInside.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public class ActivitiInside {
2626

2727
public static void main(String[] args) throws XMLStreamException {
2828

29-
String filePath="";
30-
String processId="test1";
29+
String filePath="E:/icode/codeRepository/activitiInside.bpmn";
30+
String processId="Process_1";
3131
Map<String,Object> variables = new HashMap<>();
32-
variables.put("name","tt");
32+
variables.put("name","1");
3333
// 加载流程文件 BPMN标准
3434
InputStream fileinputStream = loadFile(filePath);
3535
// 装载BPMN模型
@@ -46,18 +46,22 @@ public static void main(String[] args) throws XMLStreamException {
4646
for(FlowElement flowElement : flowList){
4747
if(flowElement instanceof StartEvent){ // 开始节点
4848
startEvent = (StartEvent) flowElement;
49+
break;
4950
}
5051
if(flowElement instanceof SubProcess){ // 子流程
5152
subProcess = (SubProcess) flowElement;
5253
}
5354
}
5455

5556
// 获取后续节点
56-
getNextEvent(startEvent.getId(),process,variables);
57+
String nextId = getNextEvent(startEvent.getId(),process,variables);
58+
while(nextId !=null){
59+
nextId = getNextEvent(nextId,process,variables);
60+
}
5761
}
5862

5963
// 获取后续节点
60-
private static void getNextEvent(String eventId,Process process,Map<String,Object> variables){
64+
private static String getNextEvent(String eventId,Process process,Map<String,Object> variables){
6165
FlowElement nowflowElement = process.getFlowElement(eventId);
6266
FlowNode flowNode = (FlowNode) nowflowElement;
6367
List<SequenceFlow> nextFlows = flowNode.getOutgoingFlows();// 连接线
@@ -76,13 +80,16 @@ private static void getNextEvent(String eventId,Process process,Map<String,Objec
7680
String elementId = sequenceFlow.getTargetRef(); // 任务节点,打印任务参数
7781
FlowElement flowElement = process.getFlowElement(elementId);
7882
if(flowElement instanceof Task){
83+
Task task = (Task)flowElement;
7984
//捞取节点参数
80-
// flowElement.getExtensionElements().get("property");
81-
String name = flowElement.getAttributeValue(null,"name");
82-
String value =flowElement.getAttributeValue(null,"value");
85+
List<ExtensionElement> list = task.getExtensionElements().get("properties");
86+
String name = task.getAttributeValue(null,"name");
87+
String value =task.getAttributeValue(null,"value");
8388
System.out.println("name:"+name+",value:"+value);
89+
return elementId;
8490
}
8591
}
92+
return null;
8693
}
8794

8895
private static InputStream loadFile(String filePath){
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.code.repository.test;
2+
3+
/**
4+
* 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。
5+
*
6+
* 找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为0。)
7+
*
8+
* 示例 1:
9+
*
10+
* [[0,0,1,0,0,0,0,1,0,0,0,0,0],
11+
* [0,0,0,0,0,0,0,1,1,1,0,0,0],
12+
* [0,1,1,0,1,0,0,0,0,0,0,0,0],
13+
* [0,1,0,0,1,1,0,0,1,0,1,0,0],
14+
* [0,1,0,0,1,1,0,0,1,1,1,0,0],
15+
* [0,0,0,0,0,0,0,0,0,0,1,0,0],
16+
* [0,0,0,0,0,0,0,1,1,1,0,0,0],
17+
* [0,0,0,0,0,0,0,1,1,0,0,0,0]]
18+
* 对于上面这个给定矩阵应返回 6。注意答案不应该是11,因为岛屿只能包含水平或垂直的四个方向的‘1’。
19+
*
20+
* 示例 2:
21+
*
22+
* [[0,0,0,0,0,0,0,0]]
23+
* 对于上面这个给定的矩阵, 返回 0。
24+
*/
25+
public class MaxAreaOfIsland {
26+
27+
public static void main(String[] args) {
28+
int[][] grid = new int[][]{{0,0,1,0,0,0,0,1,0,0,0,0,0},
29+
{0,0,0,0,0,0,0,1,1,1,0,0,0},
30+
{0,1,1,0,1,0,0,0,0,0,0,0,0},
31+
{0,1,0,0,1,1,0,0,1,0,1,0,0},
32+
{0,1,0,0,1,1,0,0,1,1,1,0,0},
33+
{0,0,0,0,0,0,0,0,0,0,1,0,0},
34+
{0,0,0,0,0,0,0,1,1,1,0,0,0},
35+
{0,0,0,0,0,0,0,1,1,0,0,0,0}};
36+
System.out.println(maxAreaOfIsland(grid));
37+
}
38+
39+
public static int maxAreaOfIsland(int[][] grid) {
40+
int max =0;
41+
int area = 0;
42+
for(int i=0;i<grid.length;i++){
43+
for(int j=0;j<grid[0].length;j++){
44+
if(grid[i][j]==1){ // 向四周确认是否都是1
45+
area = confirm(grid,i,j);
46+
max = max>area ?max:area;
47+
}
48+
}
49+
}
50+
return max;
51+
}
52+
53+
public static int confirm(int[][] grid,int i,int j){
54+
if(i<0 || i==grid.length){
55+
return 0;
56+
}
57+
if(j<0 || j==grid[0].length){
58+
return 0;
59+
}
60+
if(grid[i][j]==1){
61+
grid[i][j]=2;
62+
int area = 1+confirm(grid,i-1,j)+confirm(grid,i+1,j)+confirm(grid,i,j-1)+confirm(grid,i,j+1);
63+
return area;
64+
}
65+
return 0;
66+
}
67+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.code.repository.test;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Repeat {
7+
8+
public static void main(String[] args) {
9+
String s = "1111";
10+
List<String> result = restoreIpAddresses(s);
11+
for(String ip : result){
12+
System.out.println(ip);
13+
}
14+
}
15+
16+
public static List<String> restoreIpAddresses(String s){
17+
List<String> result = new ArrayList<>();
18+
// 255 255 255 255 IP地址分为4段,每段最多3位数,每段数字值的范围 0-2555
19+
// 分段处理,递归处理每一段,最后一段拼接结果
20+
addNextSegment(s,1,0,"",result);
21+
return result;
22+
}
23+
24+
/**
25+
* 添加下一段
26+
* @param s
27+
* @param seg 段号
28+
* @param pos 已使用位置
29+
* @param preStr 前序段ip
30+
* @param result 最终结果
31+
*/
32+
public static void addNextSegment(String s,int seg ,int pos,String preStr,List<String> result){
33+
if(seg>4 || pos>=s.length()){// 超过范围边界
34+
return;
35+
}
36+
String nowStr ="";
37+
if(seg == 4){// 如果是第4段,判断剩余字符串是否ok
38+
nowStr = s.substring(pos,s.length());
39+
if(nowStr.length()>3 || nowStr.length()>1 && nowStr.charAt(0)=='0'){// 不是1位且0开头不合法
40+
return;
41+
}
42+
Integer num = new Integer(nowStr);
43+
if(num >=0 && num<=255){ // 符合数字大小范围,加上前序字符,加到结果中
44+
result.add(preStr+nowStr);
45+
}
46+
return; // 到第4段结束
47+
}
48+
49+
seg++;
50+
// 本段取1位,不会有0开头问题,不会有值范围问题
51+
if(pos+1<=s.length()){
52+
nowStr = s.substring(pos,pos+1);
53+
addNextSegment(s,seg,pos+1,preStr+nowStr+".",result);
54+
}
55+
// 本段取2位,需校验0开头问题
56+
if(pos+2<=s.length()){
57+
nowStr = s.substring(pos,pos+2);
58+
if(nowStr.length() >1 && nowStr.charAt(0)=='0'){// 0开头非法,直接范围,不需要进行取3位验证
59+
return;
60+
}
61+
addNextSegment(s,seg,pos+2,preStr+nowStr+".",result);
62+
}
63+
// 本段取3位,需校验值范围问题
64+
if(pos+3<=s.length()){
65+
nowStr = s.substring(pos,pos+3);
66+
Integer num = new Integer(nowStr);
67+
if(num>=0 && num<=255){// 值范围是否合法
68+
addNextSegment(s,seg,pos+3,preStr+nowStr+".",result);
69+
}
70+
}
71+
}
72+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.code.repository.test;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* 给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。
8+
*
9+
* 输入: "25525511135"
10+
* 输出: ["255.255.11.135", "255.255.111.35"]
11+
*/
12+
public class RestoreIpAddresses {
13+
14+
public static void main(String[] args) {
15+
String s = "25525511135";
16+
List<String> result = restoreIpAddresses(s);
17+
for(String ip : result){
18+
System.out.println(ip);
19+
}
20+
}
21+
22+
public static List<String> restoreIpAddresses(String s){
23+
List<String> result = new ArrayList<>();
24+
// 255 255 255 255 IP地址分为4段,每段最多3位数,每段数字值的范围 0-2555
25+
// 分段处理,递归处理每一段,最后一段拼接结果
26+
addNextSegment(s,1,0,"",result);
27+
return result;
28+
}
29+
30+
/**
31+
* 添加下一段
32+
* @param s
33+
* @param seg 段号
34+
* @param pos 已使用位置
35+
* @param preStr 前序段ip
36+
* @param result 最终结果
37+
*/
38+
public static void addNextSegment(String s,int seg ,int pos,String preStr,List<String> result){
39+
if(seg>4 || pos>=s.length()){// 超过范围边界
40+
return;
41+
}
42+
String nowStr ="";
43+
if(seg == 4){// 如果是第4段,判断剩余字符串是否ok
44+
nowStr = s.substring(pos,s.length());
45+
if(nowStr.length()>3 || nowStr.length()>1 && nowStr.charAt(0)=='0'){// 不是1位且0开头不合法
46+
return;
47+
}
48+
Integer num = new Integer(nowStr);
49+
if(num >=0 && num<=255){ // 符合数字大小范围,加上前序字符,加到结果中
50+
result.add(preStr+nowStr);
51+
}
52+
return; // 到第4段结束
53+
}
54+
55+
seg++;
56+
// 本段取1位,不会有0开头问题,不会有值范围问题
57+
if(pos+1<=s.length()){
58+
nowStr = s.substring(pos,pos+1);
59+
addNextSegment(s,seg,pos+1,preStr+nowStr+".",result);
60+
}
61+
// 本段取2位,需校验0开头问题
62+
if(pos+2<=s.length()){
63+
nowStr = s.substring(pos,pos+2);
64+
if(nowStr.length() >1 && nowStr.charAt(0)=='0'){// 0开头非法,直接范围,不需要进行取3位验证
65+
return;
66+
}
67+
addNextSegment(s,seg,pos+2,preStr+nowStr+".",result);
68+
}
69+
// 本段取3位,需校验值范围问题
70+
if(pos+3<=s.length()){
71+
nowStr = s.substring(pos,pos+3);
72+
Integer num = new Integer(nowStr);
73+
if(num>=0 && num<=255){// 值范围是否合法
74+
addNextSegment(s,seg,pos+3,preStr+nowStr+".",result);
75+
}
76+
}
77+
}
78+
79+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.code.repository.test;
2+
3+
public class ReverseWords {
4+
5+
public static void main(String[] args) {
6+
String str = " this is a word!";
7+
System.out.println(reverseWords(str));
8+
}
9+
10+
public static String reverseWords(String s) {
11+
String[] strArray = s.split(" ");
12+
StringBuilder sb = new StringBuilder();
13+
for(int i = strArray.length-1;i>=0;i--){
14+
if(!strArray[i].equals("")){
15+
sb.append(strArray[i]);
16+
sb.append(" ");
17+
}
18+
}
19+
if(sb.length()>0){
20+
sb.delete(sb.length()-1,sb.length());
21+
}
22+
23+
return sb.toString();
24+
}
25+
}

0 commit comments

Comments
 (0)