zoukankan      html  css  js  c++  java
  • 孩子作业:DEV C++ 八进制转二进制

    #include<bits/stdc++.h>
    using namespace std;
    int a[10005],b[8];
    int main()
    {
    string str_d;
    int n,d,an=0;
    cin>>n;
    if(n>=10)
    {
    return 0;
    }
    cin>>str_d;

    for(int i=0;i<n;i++)
    {
    int v=int(str_d[i]-48);
    if(v>7)
    {
    return 0;
    }
    int s=v/2;
    int js=0;
    b[js]=v%2;
    while(s!=0)
    {

    js++;
    if(s<2)
    {
    s=s/2;
    b[js]=1;
    //js++;
    //b[js]=0;
    //cout<<s<<" "<<b[js]<<" a ";
    }
    else
    {

    b[js]=s%2;
    s=s/2;
    //cout<<" s:"<<s<<" "<<b[js]<<" e";
    }


    }

    while(js<3)//补全0
    {
    js++;
    b[js]=0;
    }
    //cout<<" "<<js<<endl;
    for(int p=0;p<=2;p++)
    {
    a[an]=b[2-p];
    //cout<<b[p];
    //cout<<a[an]<<" ";
    an++;
    }
    //cout<<endl;
    }
    int jz=0;
    for(int i=0;i<an;i++)
    {
    if(a[i]==1)
    {
    jz=1;
    }
    if(jz==1)cout<<a[i];
    }
    return 0;
    }

  • 相关阅读:
    markdown keynote
    pyecharts
    运行成功
    python发邮件3
    python发邮件2
    python发邮件1
    python发邮件
    python中的编码声明
    auther tonyxiao
    111
  • 原文地址:https://www.cnblogs.com/zdc-shine/p/11306067.html
Copyright © 2011-2022 走看看