文章
7
粉丝
502
获赞
4
访问
26.0k
 
#include<stdio.h>
#include <math.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int x;
    int s[4000];  
    while(cin >> x)//将x逐位分解,且x的逆序二进制数存放在s数组中
    {
        int cnt=0;//数组下标
        int len = 0;//记录数组长度 
		while (x > 0)
		{
			int w=(x % 2);
	        if (w < 10) s[cnt++] = w + '0';
	        else s[cnt++] = (w - 10) + 'A';
	        x /= 2;
	        len = cnt; 
		}
		int ans = 0;
	    for(int i = 0;i < len; i++)//转换为10进制 
	    {
	       ans = ans * 2;
	       if (s[i] >= '0' && s[i] <= '9')	ans += (s[i] - '0');
	       else ans += (s[i] - 'A') + 10;
	    }
	    cout << ans;		
    }
    return 0;  
}
OJ显示Presentation Error,但我输入173,输出是和样例一致的。不知道问题出在哪
登录后发布评论
你的输出没有换行,多组输入的时候会导致输出结果连在一起。