import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int m = input.nextInt(); int n = input.nextInt(); int[] a = new int[m + n]; for (int i = 0; i < m + n; i++) { if (i < m) { a[i] = input.nextInt(); } else { a[i] = 0; } } int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = input.nextInt(); } int m1 = input.nextInt(); int n1 = input.nextInt(); if (n1 == 0) // 当n1为0时 ,输出a 数组; { for (int i = 0; i < m; i++) { if (i == 0) { System.out.print(a[i]); } else { System.out.print("," + a[i]); } } } else { Add(a, m1, b, n1); } } public static void Add(int a[], int m1, int b[], int n1) { int[] c = new int[n1]; int x = m1 + n1; for (int i = 0; i < n1; i++) { c[i] = b[i]; } for (int i = 0; i < n1; i++) { if (m1 < x) { a[m1] = c[i]; m1++; } } for (int i = 0; i < x; i++) { if (i == 0) { System.out.print(a[i]); } else { System.out.print("," + a[i]); } } } }
解题思路:
正常思路, 注意n1 为零的时候, 直接输出a数组;
注意事项:
参考代码:
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:570 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:639 |
【偶数求和】 (C++代码)浏览:721 |
时间转换 (Java代码)浏览:587 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:903 |
【矩阵】 (C++代码)浏览:959 |
Hello, world! (C语言代码)浏览:725 |
字符逆序 (C语言代码)浏览:467 |
数字游戏 (C++代码)浏览:1204 |
sizeof的大作用 (C语言代码)浏览:1071 |