博客
关于我
PAT 1027 Colors in Mars
阅读量:794 次
发布时间:2023-02-26

本文共 2477 字,大约阅读时间需要 8 分钟。

C语言编程技巧
                                    #include <div>                                    #include <stdio.h>                                    #include <iostream>                                    #include <cstdlib>                                    using namespace std;                                    char tbl[] = {                                        '0', '1', '2', '3',                                         '4', '5', '6', '7',                                         '8', '9', 'A', 'B', 'C'                                    };                                    void d213(int d, int &m, int &l) {                                        l = d % 13;                                        m = d / 13;                                    }                                    void print13(int m, int l) {                                        printf("%c%c", tbl[m], tbl[l]);                                    }                                    int main() {                                        int d = 0;                                        int m, l;                                        printf("#");                                        for (int i=0; i<3; i++) {                                            scanf("%d", &d);                                            d213(d, m, l);                                            print13(m, l);                                        }                                        return 0;                                    }                                

这段代码展示了如何将一个数字分解为模13和整除13的两部分,并将结果以特定的字符表示输出。这是一个非常直观的编程示例,适合学习C语言的新手。

代码中的关键部分包括:

  • tbl数组用于映射数字与字符
  • d213函数负责将数字分解
  • print13函数负责输出结果
  • main函数作为程序入口

这个程序通过循环读取输入并逐步分解数字,最终生成一个由两个字符组成的字符串输出。这种方法在处理较大数字时非常高效。

转载自:https://www.cnblogs.com/lailailai/p/4069811.html

你可能感兴趣的文章
Passport 密码模式
查看>>
Spring Boot(七十六):集成Redisson实现布隆过滤器(Bloom Filter)
查看>>
passport 简易搭配
查看>>
passwd命令限制用户密码到期时间
查看>>
Spring Boot 动态加载jar包,动态配置太强了!
查看>>
Spring @Async执行异步方法的简单使用
查看>>
PAT (Basic Level) Practice 乙级1021-1030
查看>>
PAT (Basic Level) Practice 乙级1031-1040
查看>>
PAT (Basic Level) Practice 乙级1041-1045
查看>>
SparkSql的元数据
查看>>
PAT (Basic Level) Practice 乙级1051-1055
查看>>
PAT (Basic Level) Practise - 写出这个数
查看>>
PAT 1027 Colors in Mars
查看>>
PAT 1127 ZigZagging on a Tree[难]
查看>>
PAT 2-07. 素因子分解(20)
查看>>
PAT A1033 重点题
查看>>
SparkSQL学习03-数据读取与存储
查看>>
PAT L2-012. 关于堆的判断
查看>>
PAT Spell It Right [非常简单]
查看>>
PAT-1044. Shopping in Mars (25)
查看>>