解题思路: 因为数组后移之后,最后面的数又要放到前面,所以开始想到了循环链表,奈何我不会,所以使用了数组拷贝的方式,分别对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二级辅导-同因查找 (C语言代码)浏览:585 |
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:774 |
WU-格式化数据输出 (C语言代码)浏览:1755 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:542 |
Hello, world! (C++代码)浏览:1744 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:545 |
蛇行矩阵 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:2092 |
1011题解浏览:765 |