当前位置:网站首页>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();
}
}
边栏推荐
- Junit多线程的写法
- 【Optional】1. Map and ifpresent 2 Ofnullable and orelse
- Left aligned, right aligned, random number, goto, compare output bool
- [spark][core] interview questions talk about push based shuffle
- [LDA] basic knowledge notes - mainly AE and VAE
- 【LDA】基础知识笔记——主要是AE、VAE
- Industrial end: a new battlefield of 618
- Serialization and deserialization mechanism in terms of games
- [wechat applet] 3 The first wechat applet
- 数据的收集
猜你喜欢
随机推荐
Thinking: what is asynchrony and thread safety
三维重建系统 | L3增量运动恢复结构(增量SFM)
[gatewaysessioninactiveevent event] 1 Connect your own client disconnect
Shardingsphere practice (6) - elastic scaling
Left aligned, right aligned, random number, goto, compare output bool
指针相关概念
解决log4j2漏洞遭到挖矿、僵尸进程病毒攻击
[lambda operation jcf]
selenium之元素定位
【Optional】1. Map and ifpresent 2 Ofnullable and orelse
基于TensorRT的深度学习模型部署实战教程!
Alibaba, Tencent et pingduo sont à la recherche d'une nouvelle logique pour l'Internet industriel
Yiwei lithium energy plans to raise 9billion yuan: liujincheng and luojinhong jointly subscribe for 6billion yuan of layout Optical Valley
Scala下载及IDEA安装Scala插件(保姆级教程超详细)
ngork实现内网穿透--免费
Junit测试中常用的断言
webdriver入门
Phpstudy indicates that the hosts file may not exist or be blocked from being opened. How to resolve the failure of synchronizing hosts
阿裏、騰訊、拼多多垂範,產業互聯網的新邏輯漸顯
New features of ES6









