7 条题解

  • 4
    @ 2023-10-24 18:22:55

    平平无奇

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        short n, cnt, a[1005];
        cin >> n;
        while (n)
        {
            a[++cnt] = n % 2;
            n /= 2;
        }
        for (int i = cnt; i >= 1; i--)
            cout << a[i];
        return 0;
    }
    
    • 4
      @ 2023-8-28 10:47:44
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n, a[100005], cnt = 0;
          cin >> n;
          while(n)
          {
              a[++cnt] = n % 2;
              n /= 2;
          }
          for (int i = cnt; i >= 1; i--)
              cout << a[i];
          return 0;
      }
      
      • 3
        @ 2023-8-16 9:44:18
        #include <bits/stdc++.h>
        using namespace std;
        int n,a[10005],x;
        int main()
        {
            cin>>n;
            while(n!=0)
            {
                a[x]=n%2;
                n/=2;
                x++;
            }
            for(int i=x-1;i>=0;i--) cout<<a[i];
            return 0;
        }
        
        • 3
          @ 2022-12-20 9:12:35
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              int x, a[105], i = 0, k, n;
              cin >> x;
              n = x;
              do
              {
                  k = n % 2;
                  a[i] = k;
                  i++;
                  n /= 2;
              } while(n > 0);
              for (int j = i - 1; j >= 0; j--)
              {
                  cout << a[j];
              }
              return 0;
          }
          
          • 2
            @ 2024-4-6 18:22:15
            #include<iostream>
            using namespace std;
            int n,k,a[100005];
            int main(){
                cin>>n;
                while(n!=0){
                    a[++k]=n%2;//存储余数
                    n/=2;
                }//短除法
                for(int i=k;i>=1;i--)//倒序输出
                    cout<<a[i];
                return 0;
            }//编者:Royal
            
            • 0
              @ 2024-6-8 18:37:11

              404啦

              • 0
                @ 2024-5-6 20:58:08
                #include <bits/stdc++.h>
                using namespace std;
                int n;
                string t(int x){
                	string rep;
                	while (x>0){
                		rep+=(x%2+'0');
                		x/=2;
                	}
                	reverse(rep.begin(),rep.end());
                	return rep;
                }
                int main(){
                	cin>>n;
                	cout<<t(n);
                	return 0;
                }
                
                • 1

                【入门】正整数N转换成一个二进制数

                信息

                ID
                108
                时间
                1000ms
                内存
                16MiB
                难度
                3
                标签
                递交数
                226
                已通过
                115
                上传者