当前位置:网站首页>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 
边栏推荐
- Error reporting in Luban H5 installation
- 传统微服务框架如何无缝过渡到服务网格 ASM
- Understand the module function of MES management system
- The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
- Mysql 监控6
- C语言 数组元素循环右移问题
- Sklearn notes: make_ Blobs generate clustering data
- 【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题
- [recommendation system] concise principle and code implementation of user based collaborative filtering
- 关于c语言main函数中int argc,char **argv的理解
猜你喜欢

Cub school learning: manual query and ADC in-depth use

The first technology podcast month will begin soon

JS prototype and prototype chain (Lantern Festival meal)

Cookie encryption 13
![[machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems](/img/ec/de75eb8279604a57ef7d90406ad7c7.png)
[machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems

C语言 写出这个数

R language linear regression model fitting diagnosis outliers analysis of domestic gas consumption and calorie examples with self-test questions

cookie加密9

首届·技术播客月开播在即

C语言 成绩排名
随机推荐
Varnish 基础概览7
Varnish foundation overview 6
postman 之接口关联
cookie加密11
[535. encryption and decryption of tinyurl]
The unity editor randomly generates objects. After changing the scene, the problem of object loss is solved
Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases
Sentinel source code analysis Part 8 - core process - sphu Entry current limiting execution
Varnish 基础概览3
[Thesis Writing] English thesis writing guide
Embedded test template
Can mango hypermedia, which "braves the wind and waves", go ashore?
挖财的课程靠谱吗,让开户安全吗?
Interview summary
关于c语言main函数中int argc,char **argv的理解
Stringredistemplate disconnects and the value disappears
TP-LINK configure WiFi authentication method for wireless Internet SMS
JS prototype and prototype chain (Lantern Festival meal)
Varnish foundation overview 5
C语言 我要通过