AuAu


私信TA

用户名:Alanwjs

访问量:5919

签 名:

上面那位兄弟,你的头被脑袋踢了

等  级
排  名 1473
经  验 2759
参赛次数 3
文章发表 10
年  龄 0
在职情况 学生
学  校 烟台大学
专  业 软件工程

  自我简介:

解题思路:
一定要注意,此题不是简单的左右移位,而是循环移位,我的题解都进行了注释,欢迎各位点评
参考代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int move(int value,int n)
{
	int a=0,j=0;
	int b[100]={};
	if(n<0) n=n+32;//转化为唯一的右移 
	while(value!=0)//求解2进制各个位上数,并保存在数组b[]中 
	{
		b[j++]=value%2;
		value/=2;
	}
	int t;
	for(int j=0;j<n;j++)//循环移动n次 
	{
		t=b[0];//提前保存b[0]; 
		for(int i=0;i<31;i++)//一次移动一位,保存最后一位,以便放到第一位
		{
			b[i]=b[i+1];			
		}
		b[31]=t;
	}
	for(int i=0;i<32;i++)
	{
		if(b[i]!=0)
			a=a+(int)pow(2,i)*b[i];
	} 
	return a;
}
int main() {
	int m,n;
	scanf("%u%d",&m,&n);
	int a=move(m,n);
	printf("%u\n",a); 
	return 0;
}

   我这么用心,要记得留赞评论哦~

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

哪里有不理解的地方,一定要提哦
2018-03-22 19:11:05
  • «
  • 1
  • »