PAT (Basic Level) Practise (中文) 1008. 数组元素循环右移问题 (20)
2017-08-29 16:33
387 查看
1008. 数组元素循环右移问题 (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?
输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输入N个整数,之间用空格分隔。
输出格式:在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。
输入样例:
6 2 1 2 3 4 5 6
输出样例:
5 6 1 2 3 4
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int step=input.nextInt(); int [] arr=new int ; int [] arr2=new int ; for (int i = 0; i < n; i++) { arr[i]=input.nextInt(); } for (int i = 0; i < n; i++) { arr2[(i+step)%n]=arr[i]; } for (int i = 0; i < arr2.length; i++) { System.out.print(arr2[i]); if (i<n-1) { System.out.print(" "); } } } }
相关文章推荐
- PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题 (20)
- PAT (Basic Level) Practise (中文)- 1008. 数组元素循环右移问题 (20)
- PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题 (20)
- PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题 (20) C语言
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题
- PAT (Basic Level) Practise-1008. 数组元素循环右移问题 (20)
- PAT (Basic Level) Practise 的C++实现-1008. 数组元素循环右移问题
- PAT (Basic Level) Practise:1008. 数组元素循环右移问题
- PAT Basic Level 1008. 数组元素循环右移问题 (20)
- 【C++】浙大basic level PAT 1008. 数组元素循环右移问题 (20)*
- PAT BASIC LEVEL 1008. 数组元素循环右移问题 (20)
- PAT1008 BASIC:数组元素循环右移问题 (20)
- PAT(basic level) 1008 数组元素循环右移问题
- Pat(Basic Level)Practice--1008(数组元素循环右移问题)
- PAT Basic 1008. 数组元素循环右移问题 (20)
- 浙江大学PAT---Basic Level---1008----数组元素循环右移问题
- PAT Basic 1008. 数组元素循环右移问题 (20)
- PAT (Basic Level)1008. 数组元素循环右移问题
- PATBasic——1008. 数组元素循环右移问题 (20)
- PAT(Basic Level)_1008_数组元素循环右移问题