解题思路: 因为数组后移之后,最后面的数又要放到前面,所以开始想到了循环链表,奈何我不会,所以使用了数组拷贝的方式,分别对m前后进行拷贝即可
注意事项: 注意拷贝时候,长度参数和起始位置参数的计算
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();//n个整数
int[] a = new int[n];
for(int i =0;i<n;i++)
a[i] = scanner.nextInt();//数组存储n个整数
int m =scanner.nextInt();//移动m个位置
hy(a,m);
}
static void hy(int [] a,int m){
int [] b =new int[a.length];
System.arraycopy(a,0,b,m,b.length-m);
System.arraycopy(a,a.length-m,b,0,m);
for (int i =0;i<b.length;i++ )
System.out.print(b[i] + " ");
}
}
// =============Dragon be here!==========/
// ┏┓ ┏┓
// ┏┛┻━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ┃ ┳┛ ┗┳ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃神兽保佑
// ┃ ┃代码无BUG!
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
// ━━━━━━神兽出没━━━━━━
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:624 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:464 |
DNA (C语言描述,蓝桥杯)浏览:1553 |
蚂蚁感冒 (C语言代码)浏览:1319 |
蚂蚁感冒 (C语言代码)浏览:768 |
C二级辅导-阶乘数列 (C语言代码)浏览:508 |
字符串的输入输出处理 (C语言代码)浏览:984 |
永远的丰碑 (C语言代码)浏览:516 |
C语言训练-8除不尽的数 (C语言代码)浏览:1396 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:455 |