ZZULIOJ 1124: 两个有序数组合并,Java

1124: 两个有序数组合并

import java.io.*;
import java.util.Scanner;
public class Main {
    static Scanner cin = new Scanner(System.in);
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException{
        int m=cin.nextInt();
        int []a = new int[m+1];
        for(int i=m;i>=1;i--) a[i]=cin.nextInt();
        int n=cin.nextInt();
        int []b = new int[n+1];
        for(int i=1;i<=n;i++) b[i]=cin.nextInt();
        int []c = new int[m+n+1];
        int s=1,t=1,k=1;
        while(s<=m&&t<=n)
        {
            if(a[s]>=b[t]) c[k++]=a[s++];
            else c[k++]=b[t++];
        }
        while(s<=m) c[k++]=a[s++];
        while(t<=n) c[k++]=b[t++];
        for(k=1;k<=m+n;k++)
            bw.write(c[k]+" ");
        bw.flush();
    }
}

你可能感兴趣的:(#,Java刷题,java)