解题思路: 因为数组后移之后,最后面的数又要放到前面,所以开始想到了循环链表,奈何我不会,所以使用了数组拷贝的方式,分别对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++代码)浏览:2002 |
【排队买票】 (C语言代码)浏览:899 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:594 |
C语言训练-自由落体问题 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:371 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:819 |
1024题解浏览:803 |
有关字符,字符串的输入输出函数说明浏览:477 |
蚂蚁感冒 (C语言代码)浏览:767 |
1231题解(注意理解“输入多个测试实例”)浏览:785 |