当前位置:网站首页>Pta: self test -3 array element cyclic right shift problem (20 points)
Pta: self test -3 array element cyclic right shift problem (20 points)
2022-06-12 14:59:00 【George Sumu】

Implement... With queues , However, there are some differences between the first in first out (FIFO) mechanism and the array right shift mechanism , So we moved him to the left , Because the number of digits he moves is cyclic , So we can make a left shift n-m position , Then every move n Bit is equivalent to no movement , So for n Make a balance .
#include"stdio.h"
#include"math.h"
#include <cstdlib>
#include <iostream>
#include <queue>
using namespace std;
int main(){
queue<int> q;
int n,step;
int temp;
scanf("%d%d",&n,&step);
for(int i =0;i<n;i++){
temp =0;
scanf("%d",&temp);
q.push(temp);
}
for (int i=0;i<abs(n-step%n)%n;i++){
temp = q.front();
q.pop();
q.push(temp);
}
printf("%d",q.front());
q.pop();
for(int i=1;i<n;i++){
printf(" %d",q.front());
q.pop();
}
}
边栏推荐
- Autofac Beginner (1)
- ROS 中 boost::bind( ) 的使用
- 如何写年终总结
- ADSL
- Prompt that the program cannot access key files / directories when installing PS software. Error code: 41
- New features of ES6
- [LDA] basic knowledge notes - mainly AE and VAE
- Process abstraction of program construction and interpretation
- 机器人前行、旋转的service编写
- webdriver入门
猜你喜欢

selenium之元素定位

C 数据类型

Qiming Zhixian shares the application scheme of 2.8-inch handheld central control screen

交换数字,异或求单,操作符相关

Array related content

Assertion of selenium webdriver

Left aligned, right aligned, random number, goto, compare output bool

Wild pointer understanding

解决log4j2漏洞遭到挖矿、僵尸进程病毒攻击

【LDA】LDA主题模型笔记—主要是狄利克雷
随机推荐
Qiming Zhixian shares the application scheme of 2.8-inch handheld central control screen
PTA:自测-1 打印沙漏 (20分)
Process abstraction of program construction and interpretation
结构体示例
Alibaba, Tencent and pinduoduo set an example, and the new logic of industrial Internet is gradually emerging
PTA:自测-2 素数对猜想 (20分)
[system. Currenttimemillis()] current timestamp: the number of milliseconds that have elapsed since the current system time was 0:00:00 on January 1, 1970
Common assertions in JUnit testing
ngork实现内网穿透--免费
USART (rs232422485), I2C, SPI, can, USB bus
h3c GR5200路由器上如何设置公网ip可以访问
如何写年终总结
USART(RS232422485)、I2C、SPI、CAN、USB总线
ROS初学者编写小乌龟以一定速度旋转一定角度的server
【Optional】1. Map and ifpresent 2 Ofnullable and orelse
【LDA】基础知识笔记——主要是AE、VAE
C main函数
Kinect2.0+ORBSLAM2_with_pointcloud_map
增加mysql的最大连接数
How to add WWW to the domain name