当前位置: 代码迷 >> 综合 >> ZZULIOJ 1124: 两个有序数组合并,Java
  详细解决方案

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

热度:6   发布时间:2023-11-25 07:50:28.0

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();}
}
  相关解决方案