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语言代码)浏览:1472 |
奖学金 (C++代码)浏览:2008 |
妹子杀手的故事 (C语言代码)浏览:1234 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:469 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:529 |
局部变量作函数返回值的问题浏览:981 |
输出九九乘法表 (C语言代码)浏览:1048 |
多输入输出练习2 (C语言代码)浏览:1657 |
JAM计数法 (C语言代码)浏览:671 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:564 |