当前位置:网站首页>1008 数组元素循环右移问题 (20 分)
1008 数组元素循环右移问题 (20 分)
2022-08-05 05:16:00 【呆比特】
1008 数组元素循环右移问题 (20 分)
题目要求:
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//輸入
int n = scan.nextInt();
int m = scan.nextInt();
scan.nextLine();
//直接在輸入时就按照要求的顺序保存
int [] arr = new int[n];
//n = m
if (n == m){
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
}
//防止移动数大于数组长度
int k = m % n;
for (int i = k; i < n; i++) {
arr[i] = scan.nextInt();
}
for (int i = 0; i < k; i++) {
arr[i] = scan.nextInt();
}
//输出
for (int i = 0; i < n; i++) {
if (i == n-1){
System.out.print(arr[i]);
} else{
System.out.print(arr[i] + " ");
}
}
}
}
结果:
边栏推荐
猜你喜欢

如何停止flink job

【Shell编程】第一章:子串

基于STM32F407的一个温度传感器报警系统(用的是DS18B20温度传感器,4针0.96寸OLED显示屏,并且附带日期显示)
![[Pytorch study notes] 9. How to evaluate the classification results of the classifier - using confusion matrix, F1-score, ROC curve, PR curve, etc. (taking Softmax binary classification as an example)](/img/ac/884d8aba8b9d363e3b9ae6de33d5a4.png)
[Pytorch study notes] 9. How to evaluate the classification results of the classifier - using confusion matrix, F1-score, ROC curve, PR curve, etc. (taking Softmax binary classification as an example)

Thread handler句柄 IntentServvice handlerThread

OSPF网络类型

flink实例开发-详细使用指南
![[After a 12] No record for a whole week](/img/05/df9aeb04274e308e1341020f836821.jpg)
[After a 12] No record for a whole week

关于存储IOPS你必须了解的概念

神经网络也能像人类利用外围视觉一样观察图像
随机推荐
5G中切片网络的核心技术FlexE
基于STM32F4的FFT+测频率幅值相位差,波形显示,示波器,时域频域分析相关工程
网络信息安全运营方法论 (上)
关于存储IOPS你必须了解的概念
表情捕捉的指标/图像的无参考质量评价
【Over 15】A week of learning lstm
PID详解
6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
OSPF网络类型
SSL 证书签发详细攻略
轻松接入Azure AD+Oauth2 实现 SSO
【论文阅读-表情捕捉】ExpNet: Landmark-Free, Deep, 3D Facial Expressions
[Database and SQL study notes] 9. (T-SQL language) Define variables, advanced queries, process control (conditions, loops, etc.)
八、响应处理——ReturnValueHandler匹配返回值处理器并处理返回值原理解析
Facial Motion Capture 调研
BFC详解(Block Formmating Context)
九、响应处理——内容协商底层原理
MySQL
网络ID,广播地址,掩码位数计算
[After a 12] No record for a whole week