Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAT (Basic Level)1008 数组元素循环右移问题 更为简单做法 #156

Open
miaomiaozhi opened this issue Feb 8, 2021 · 0 comments

Comments

@miaomiaozhi
Copy link

`#include
using namespace std;

int n;
int m;
int main (){
cin >> n >> m;
int q[n];
int flag = 0;
m = m % n;

    for (int i = m ; i < n ; i ++) {
        cin >> q[i];
        if (i == n - 1 && flag == 0) i = -1 , flag = 1;     //读入的时候就进行换位置 直接移到应该到的位置去
        if (i == m - 1 && flag == 1) break;         //flag 的意思是当读到数组末尾的时候重q[0] 开始读入
    }
    for (int i = 0 ; i < n ; i ++) {
        if (i != 0) cout << " " ;
        cout << q[i];
    }
cout << endl ;
return 0;

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant