乙_1008 数组元素循环右移问题 (20分)

题目:

分析:(1)不能新建数组不代表不可以扩展数组长度,多出来的空间相当于新建了一个数组。

(2)考虑数字之间关系  ,在输入时做处理**

类似于时钟, (1+2)%6=3  ............(5+2)%6=1, (6+2)%6=2 

代码:

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int arr[n];
  for(int i=0;i<n;i++)
    cin >> arr[(i+m)%n];     // key
  for(int i=0;i<n;i++){
     cout << arr[i];
     if(i!=n-1)  cout << " ";   // key
 }
 system("pause"); 
 return 0;
}

猜你喜欢

转载自www.cnblogs.com/xueshadouhui/p/12943002.html
今日推荐