PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题 (20 分)

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805316250615808

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <stack>
 7 using namespace std;
 8 int n,m;
 9 int a[105];
10 int b[105];
11 int main()
12 {
13        while(cin>>n>>m){
14            for(int i=0;i<n;i++) cin>>a[i];
15            m%=n;
16            for(int i=0;i<m;i++){
17                b[i]=a[n-m+i];
18                //cout<<b[i]<<" ";
19            }
20            for(int i=m;i<n;i++){
21                b[i]=a[i-m];
22                //cout<<b[i]<<" ";
23            }
24            for(int i=0;i<n;i++){
25                if(i==0) cout<<b[i];
26                else cout<<" "<<b[i];
27            } 
28            cout<<endl;
29        }
30     return 0;
31 }

 

上一篇:PTA - 排序2【sort()函数】


下一篇:kinect 环境搭建