• C语言程序设计算法题 -- lab07(1027 - 1030)


    1027. 二进制表示

    输入一个字符,输出其八位二进制表示。

    输入格式
    在一行输入一个可打印字符 c。

    输出格式
    在一行中输出c的二进制表示。

    #include
    int main()
    {
        char c;
        int i = 8;
        char res[8];
        scanf("%c", &c);
        while(--i != -1)
        {
            res[i] = '0' + c % 2;
            c /= 2;
        }
        printf("%s", res);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    1028. Maximum product

    Given a positive integer (), find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is , and print the maximum product.

    输入格式
    Only one line, containing the integer .

    输出格式
    Only one line, representing the maximum product.

    
    // 可能跟e的性质有关吧,反正就是尽量凑足够多的3出来,其次是2
    #include
    #include
    
    int f(int N) {
    	if (N == 1 || N == 2)
    		return N;
    	int max = N;
    	for (int i = 1; i < N; i++) {
    		int tmp = i * f(N - i);
    		if (tmp > max)
    			max = tmp;
    	}
    	return max;
    }
    
    int main()
    {
        int input;
        scanf("%d", &input);
        if(input < 4) printf("%d", input);
        else
        {
            long long pro = 1;
            while(input > 4)
            {
                input -= 3;
                pro *= 3;
            }
            pro *= input;
            printf("%lld", pro);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    1029. Compute e

    在这里插入图片描述

    #include
    int main()
    {
        double e = 0;
        int cnt = 1;
        double denominator = 1.0;
        while(1.0 / denominator > 1e-9)
        {
            e += 1.0 / denominator;
            denominator *= cnt++;
        }
        printf("%.6lf", e);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    1030. Rotate digits

    在这里插入图片描述

    #include
    // 字符串实现,其实直接开两个字符串更方便一点
    
    int main()
    {
        long long data, num, cnt = 0;
        scanf("%lld %lld", &data, &num);
        if(data < 10)
        {
            printf("1 %d", data);
            return 0;
        }
        
        
        long long tmp = data;
        char str[200];
        for(int i = 0 ; i < 200; i++) str[i] = 0;
        
        
        while(tmp)
        {
            str[100 - cnt++] = '0' + tmp % 10;
            tmp /= 10;
        }
        //字符串要倒着
        
        num %= cnt;
        for(int i = 0; i < num; i++)
        {
        //由于右转,所以是从右往左平移
            str[100 - i - cnt] = str[100 - i];
            str[100 - i] = 0;
        }
        // 去掉在开头0
        while(*(str - cnt - num + 101) == '0')
            num--;
        printf("%d %s",cnt ,(str - cnt - num + 101));
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
  • 相关阅读:
    工作中需要用到的Java知识(AQS篇)
    MySQL——GROUP BY详解与优化
    界面控件DevExpress WinForms工具栏菜单组件,模拟流行办公软件!
    c语言练习63:用malloc开辟二维数组的三种办法
    深入了解 GPU 互联技术——NVLINK
    [swift刷题模板] 树状数组(BIT/FenwickTree)
    LabVIEW电表改装与校准仿真系统
    二分查找汇总
    AWS认证SAA-C03每日一题
    UPLOAD-LABS1
  • 原文地址:https://blog.csdn.net/JamSlade/article/details/127668424