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语言代码)浏览:664 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1457 |
复数求和 (C语言代码)浏览:994 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1170 |
逆反的01串 (C语言代码)浏览:1527 |
简单的a+b (C语言代码)浏览:597 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:521 |
C语言程序设计教程(第三版)课后习题6.9 (C++代码)浏览:522 |
C语言程序设计教程(第三版)课后习题7.5 (C++代码)浏览:1460 |
简单的a+b (C语言代码)浏览:667 |