forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPinDuoDuo_1.java
More file actions
94 lines (76 loc) · 2.43 KB
/
Copy pathPinDuoDuo_1.java
File metadata and controls
94 lines (76 loc) · 2.43 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package BiShi;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
* @Classname PinDuoDuo_1
* @Description TODO
* @Date 19-7-28 下午1:48
* @Created by mao<[email protected]>
*/
public class PinDuoDuo_1 {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(new File("/home/mao/workspace/java/src/BiShi/pinduoduo1"));
while(sc.hasNextLine()){
String s1=sc.nextLine();
String s2=sc.nextLine();
String[] nums1=s1.split(" ");
if(nums1.length==1){
System.out.println(nums1[0]);
continue;
}
String[] nums2=s2.split(" ");
ArrayList<Integer> arr1=new ArrayList<>();
ArrayList<Integer> arr2=new ArrayList<>();
for(String s:nums1){
arr1.add(Integer.parseInt(s));
}
for(String s:nums2){
arr2.add(Integer.parseInt(s));
}
int index=0;
for(int i=1;i<arr1.size();i++){
if(arr1.get(i)<=arr1.get(i-1)){
index=i;
break;
}
}
if((arr1.size()>1)&&(arr1.get(0)>arr1.get(1))){
index=0;
}
Collections.sort(arr2);
int flag=0;
for(int j=arr2.size()-1;j>=0;j--){
if(index==(arr1.size()-1)){
if(arr2.get(j)>arr1.get(index-1)){
arr1.set(index,arr2.get(j));
flag=1;
break;
}
}else if(index==0){
if(arr2.get(j)<arr1.get(index+1)){
arr1.set(index,arr2.get(j));
flag=1;
break;
}
}else{
if((arr2.get(j)>arr1.get(index-1))&&((arr2.get(j)<arr1.get(index+1)))){
arr1.set(index,arr2.get(j));
flag=1;
break;
}
}
}
String res="";
if(flag==1){
for(Integer i:arr1){
res=res+i+" ";
}
System.out.println(res);
}else{
System.out.println("NO");
}
}
}
}