文章

1

粉丝

10

获赞

1

访问

72

头像
十进制和二进制 题解:
P1176 清华大学上机题
发布于2025年1月29日 22:54
阅读数 72

看到输入的大小就应该知道是大数模拟类, 需要开数组来存储和运算

#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<stack>
using namespace std;
#define M 1000000000
#define maxsize 1003
bool checkZero(int a[])
{
    for(int i=0; i<maxsize; i++)
    {
        if(a[i]!=0)
        {
            return false;
        }
    }

    return true;
}
int main()
{

    string n;
    while(cin>>n)
    {
        int a[maxsize]= {0};
        int j=maxsize-1;
        stack<int> s; // use to save binary
        for(int i=n.size()-1; i>=0; i--)
        {
            a[j]=n[i]-'0';
            j--;
        }

        while(!checkZero(a))
        {
            int carry=0;
            if(a[maxsize-1]&1==1) // odd
            {
                s.push(1);
            }
            else
            {
                s.push(0);
            }
            for(int ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发