拼多多笔试题-完全严格数组
import java.util.Arrays;
import java.util.Scanner;
public class Test {
public int[] method(int A[] ,int S[]){ if(A == null || S == null ) return null; int posA=-1; for(int i=0;i<A.length-1;i++){ if(A[i]>A[i+1]){ posA=i+1; break; } } if(posA == -1) return A; int maxValue=Integer.MIN_VALUE; for(int j=0;j<S.length;j++){ if(S[j]<A[posA-1]){ continue; } if(S[j]>A[posA-1]){ if(posA == A.length-1){ maxValue=S[j]; continue; }else if (A[posA+1]>S[j]){ maxValue=S[j]; continue; } } } if(maxValue==Integer.MIN_VALUE){ return null; } A[posA]=maxValue; return A; } public int[] inputArray() throws Exception{
// BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner=new Scanner(System.in); int A[]=null; int S[]=null; String s=""; while(scanner.hasNext()){ s=scanner.nextLine(); if(A == null){ A=processorInput(s); }else { S=processorInput(s); break; } } return method(A,sortArray(S)); } public int[] processorInput(String s){ if(s== null ||s.length() == 0 )return null; String[] str=s.split(" "); int[] temp=new int[str.length]; int i=0; for(String value:str){ temp[i++]=Integer.parseInt(value); } return temp; } public int[] sortArray(int temp[]){ if(temp == null) return null; for(int i=0;i<temp.length-1;i++){ for(int j=i+1;j<temp.length;j++){ if(temp[i]>temp[j]){ int value=temp[i]; temp[i]=temp[j]; temp[j]=value; } } } return temp; } public static void main(String[] args) throws Exception{ Test test=new Test(); /** * 入口 */ while (true){ //获取结果数组,如果数组是空,则直接返回No,否则返回数组 int[] value=test.inputArray(); if(value == null){ System.out.println("NO"); }else { System.out.println(Arrays.toString(value)); } } }
}
#拼多多##笔试题目#