https://pintia.cn/problem-sets/994805260223102976/problems/994805316250615808

一个数组A中存有N(N&gt0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A~0~ A~1~……A~N-1~)变换为(A~N-M~ …… A~N-1~ A~0~ A~1~……A~N-M-1~)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?

输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输入N个整数,之间用空格分隔。

输出格式:在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。

输入样例:

6 2
1 2 3 4 5 6

输出样例:

5 6 1 2 3 4

代码:
#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;
int a[maxn],b[maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
m=m%n;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=n-m+1;i<=n;i++)
{
//for(int j=i-n+m;j<=m;j++)
b[i-n+m]=a[i];
}
for(int i=1;i<=n-m;i++)
{
//for(int j=m+i;j<=n;j++)
b[i+m]=a[i];
}
for(int i=1;i<=n;i++)
{
if(i!=n)
printf("%d ",b[i]);
else
printf("%d",b[i]);
}
return 0;
}

  

PAT 1008 数组元素循环右移问题的更多相关文章

  1. PAT 1008 数组元素循环右移问题 (20)(代码)

    1008 数组元素循环右移问题 (20)(20 分) 一个数组A中存有N(N&gt0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A ...

  2. PAT——1008. 数组元素循环右移问题

    一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0  ...

  3. PAT 1008. 数组元素循环右移问题 (20)

    一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 ...

  4. PAT乙级 1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...

  5. PAT乙级真题1008. 数组元素循环右移问题 (20)

    原题: 1008. 数组元素循环右移问题 (20) 时间限制400 ms内存限制65536 kB 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M&g ...

  6. [C++]PAT乙级1008.数组元素循环右移问题 (20/20)

    /* 1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数, ...

  7. PAT 乙级 1008 数组元素循环右移问题 (20) C++版

    1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...

  8. 【PAT】1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN- ...

  9. PAT 乙级 1008.数组元素循环右移问题 C++/Java

    1008 数组元素循环右移问题 (20 分) 题目来源 一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A​0​​A​1​​⋯ ...

随机推荐

  1. Django基础之urls

    一  Django简介 二   视图层之应用系统 一  Django简介 Django:   urls:路径与视图函数的映射关系   views:逻辑处理   models:与数据库相关的操作   t ...

  2. 全文索引搜索whoosh

    问题 Whoosh是python中解决索引查找的模块,在讨论索引查找的文章已经对有关索引查找进行了阐述,此处具体说明Whoosh模块的应用. 思路说明 Whoosh的安装 这里有具体内容(链接被被阉割 ...

  3. UVA806-Spatial Structures(四分树)

    Problem UVA806-Spatial Structures Accept:329  Submit:2778 Time Limit: 3000 mSec Problem Description ...

  4. 20145236《网络攻防》Exp5 MSF基础应用

    20145236<网络攻防>Exp5 MSF基础应用 一.基础问题回答 解释exploit,payload,encode是什么: exploit就是负责负载有用代码的交通工具,先通过exp ...

  5. MetaMask/sw-controller

    https://github.com/MetaMask/sw-controller Service Worker Controller Used to register a service worke ...

  6. 使用RMAN Active duplicate创建异地auxiliary Database

    1g的RMAN duplicate 可以通过Active database duplicate和Backup-based duplicate两种方法实现.这里的测试使用的是Active databas ...

  7. 617. Merge Two Binary Trees

    https://www.cnblogs.com/grandyang/p/7058935.html class Solution { public: TreeNode* mergeTrees(TreeN ...

  8. WordPress数据库及各表结构分析

    默认WordPress一共有以下11个表.这里加上了默认的表前缀 wp_ . wp_commentmeta:存储评论的元数据wp_comments:存储评论wp_links:存储友情链接(Blogro ...

  9. centos7安装python3和pip3

    python3安装 1.安装准备 # 创建安装目录 mkdir /usr/local/python3 #下载python3 wget --no-check-certificate https://ww ...

  10. ingress-nginx 添加https证书

    1.配了一个证书,发现报错: kubectl logs  ingress-nginx-controller-96fnv   -n ingress-nginx unexpected error vali ...