chenxi16

导航

1008 数组元素循环右移问题

 1 #include<stdio.h>
 2 #define MAXN 102
 3 int n,a[MAXN],m;
 4 int main(){
 5     scanf("%d %d",&n,&m);
 6     int i,j;
 7     for(i=0;i<n;i++) scanf("%d",&a[i]);
 8     if(m%n==0) {
 9         for(int i=0;i<n;i++){
10             printf("%d",a[i]);
11             if(i!=n-1) printf(" ");
12         }
13     }
14     else {
15 
16         int value = m % n,count=0;
17         for(int i=n-value;i<n;i++){
18             printf("%d",a[i]);
19             count++;
20             if(count!=n) printf(" ");
21         }
22         for(int i=0;i<n-value;i++){
23             printf("%d",a[i]);
24             count++;
25             if(count!=n) printf(" ");
26         }
27     }
28     return 0;
29 }
View Code

 

posted on 2020-04-13 19:42  chenxi16  阅读(78)  评论(0编辑  收藏  举报