小编Jay*_*yco的帖子

右旋操作

int main()
{
    int shiftSteps, newposition;
    int numbers[10], numberscopy[10];
    cin >> shiftSteps;

    for (int i = 0; i < 10; i++)
        cin >> numbers[i];

    for (int i = 0; i < 10; i++)
        numberscopy[i] = numbers[i];

    //----------------------------------------

    for (int i = 0; i < 10; i++)
    {
        newposition = (i + shiftSteps) % 10;
        numbers[newposition] = numberscopy[i];
    }

     for (int i = 0; i < 10; i++)
        cout << numbers[i] << "  ";
}
Run Code Online (Sandbox Code Playgroud)

我写了这段代码,用辅助数组“numberscopy”将 10 个数字向右旋转,但我想在没有辅助数组的情况下重写代码,我不知道如何。

c++ rotation

2
推荐指数
1
解决办法
57
查看次数

标签 统计

c++ ×1

rotation ×1