当前位置:网站首页>Circular right shift of array elements in C language
Circular right shift of array elements in C language
2022-06-30 01:31:00 【Martin の Blog】
Algorithm design ideas
- set up n Number , To the right m position
- take n-m Number stored in n after ( Be careful m It may be less than n)
- Print m-n To n+n-m Location information is enough
Code
#include <stdio.h>
int main(){
int n, m, x;
int a[100];
scanf("%d", &n);
scanf("%d", &m);
if(m>n){
m = m % n;
}
for(int i=0; i<n; i++){
scanf("%d", &x);
a[i] = x;
}
for(int i=n; i<2*n-m; i++){
a[i] = a[i-n];
}
for(int i=n-m; i<2*n-m; i++){
if(i==2*n-m-1){
printf("%d", a[i]);
}else{
printf("%d ", a[i]);
}
}
return 0;
}
Running results
边栏推荐
- Precautions for postoperative fundus hemorrhage / / must see every day
- How does webapi relate to the database of MS SQL?
- The first technology podcast month will be launched soon
- Spark 离线开发框架设计与实现
- The 8th "Internet +" competition - cloud native track invites you to challenge
- Stimulus reports reporting tool, stimulus creates and builds reports
- c语言期末不挂科(上)
- Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
- MySQL monitoring 1
- Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
猜你喜欢
随机推荐
Varnish foundation overview 7
Varnish 基础概览4
GeoTools WKT坐标系转换
C language selection, loop overview
[machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems
MySQL monitoring 6
Seata 与三大平台携手编程之夏,百万奖金等你来拿
MySQL monitoring 5
Varnish foundation overview 3
Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
Machinery -- nx2007 (UG) finite element analysis tutorial 1 -- simple object
Pytroch Learning Notes 6: NN network layer convolution layer
Storage engine analysis
C语言 写出这个数
Cookie encryption 12
传统微服务框架如何无缝过渡到服务网格 ASM
The 8th "Internet +" competition - cloud native track invites you to challenge
【机器学习Q&A】准确率、精确率、召回率、ROC和AUC
Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
Varnish foundation overview 10