首页 > 其他 > 详细

蓝桥杯 试题 基础练习 01字串

时间:2020-03-04 14:30:36      阅读:144      评论:0      收藏:0      [点我收藏+]

试题 基础练习 01字串

技术分享图片

 

 思路:我们观察下样例,其实就是0~31的二进制,并且前面补0.所以

#include<iostream>
#include<algorithm>

using namespace std;

int decToBin(int dec){
    int result = 0, temp = dec, j = 1;
    while (temp){
        result = result + j * (temp % 2);
        temp = temp / 2;
        j = j * 10;
    }
    return result;
}
int main(){

    int i;
    for (i = 0; i < 32; i++){
        printf("%05d\n", decToBin(i));
    }

    system("pause");
    return 0;
}

 

方法便有了

 

蓝桥杯 试题 基础练习 01字串

原文:https://www.cnblogs.com/pcdl/p/12408613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!