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

</pre>一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A<sub style="line-height:0">0</sub>A<sub style="line-height:0">1</sub>……A<sub style="line-height:0">N-1</sub>)变换为(A<sub style="line-height:0">N-M</sub> …… A<sub style="line-height:0">N-1</sub> A<sub style="line-height:0">0</sub> A<sub style="line-height:0">1</sub>……A<sub style="line-height:0">N-M-1</sub>)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?<p></p><p style="margin-top:0px; margin-bottom:1.5em; padding-top:0px; padding-bottom:0px; border:0px; font-family:'Droid Sans',Verdana,'Microsoft YaHei',Tahoma,sans-serif; line-height:18px; vertical-align:baseline; color:rgb(51,51,51); background-color:rgb(250,250,250)"><strong>输入格式:</strong>每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输入N个整数,之间用空格分隔。</p><p style="margin-top:0px; margin-bottom:1.5em; padding-top:0px; padding-bottom:0px; border:0px; font-family:'Droid Sans',Verdana,'Microsoft YaHei',Tahoma,sans-serif; line-height:18px; vertical-align:baseline; color:rgb(51,51,51); background-color:rgb(250,250,250)"><strong>输出格式:</strong>在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。</p><span style="color:rgb(51,51,51); font-family:'Droid Sans',Verdana,'Microsoft YaHei',Tahoma,sans-serif; line-height:18px; background-color:rgb(250,250,250)">输入样例:</span><pre style="margin-top:1.5em; margin-bottom:1.5em; padding:0px; border:0px; font-family:'Droid Sans Mono',Consolas,'Courier New',monospace; line-height:18px; vertical-align:baseline; overflow:auto; color:rgb(51,51,51); background-color:rgb(250,250,250)">6 2
1 2 3 4 5 6
输出样例:

5 6 1 2 3 4

代码如下:

#include<stdio.h>
main()
{
	int m[200];

	int n,wm,/**p*/i;
	scanf("%d",&n);
	scanf("%d",&wm);
	for(i=0;i<n;i++)
	{
	
		scanf("%d",&m[i]);
	}
	wm=wm%n;

	
/*	for(i=0;i<n-wm;i++);
	{
		p++;
	}*/
	for(i=n-wm;i<n;i++)
	{
		printf("%d ",m[i]);

	}
	for(i=0;i<n-wm;i++)
	{
		if(i==(n-wm-1))
		{
			printf("%d",m[i]);
		}
		else
			printf("%d ",m[i]);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值