PAT (Advanced Level) Practise - 1005. Spell It Right (20)

本文介绍了一个编程问题,即给定一个非负整数N,计算其所有位数的和,并将该和的每一位数字用英文单词表示出来。输入为一个大整数,输出则是该整数各位相加后的和的每一位数字的英文单词形式。

1005. Spell It Right (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line. 

Sample Input:
12345
Sample Output:
one five

把每位上的数加起来,变成单个英文输出。


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
using namespace std;
const int maxn = 100100;
#define LL long long
int main()
{
    char s[111];
    scanf("%s",s);
    int now=0;
    int len=strlen(s);
    for(int i=0;i<len;i++){
        now+=s[i]-'0';
    }
    if(now==0){
        printf("zero\n");
        return 0;
    }
    int num[111];
    int cnt=0;
    while(now){
        num[++cnt]=now%10;
        now/=10;
    }
    map<int,string> mp;
    mp[0]="zero";
    mp[1]="one";
    mp[2]="two";
    mp[3]="three";
    mp[4]="four";
    mp[5]="five";
    mp[6]="six";
    mp[7]="seven";
    mp[8]="eight";
    mp[9]="nine";
    for(int i=cnt;i>=1;i--){
        if(i!=cnt)  printf(" ");
       cout<<mp[num[i]];
    }


}



### Keil C51 编译时找不到 `reg51.h` 文件的问题解决方案 当在 Keil C51 中遇到错误提示:“error: #5: cannot open source input file 'reg51.h': No such file or directory”,这通常表明编译器无法找到所需的头文件 `reg51.h`。以下是可能导致该问题的原因以及对应的解决方法。 #### 原因分析 1. **未安装标准设备支持包** 如果没有正确安装或配置 Keil 的标准设备支持包,则可能缺少必要的头文件,例如 `reg51.h`[^1]。 2. **项目设置中的路径缺失** 即使 `reg51.h` 存在于系统中,但如果项目的包含路径未正确指向这些文件的位置,也会导致类似的错误[^2]。 3. **目标芯片不匹配** 在某些情况下,如果选择了错误的目标芯片型号或者未启用正确的设备选项,也可能引发此类问题[^3]。 4. **Keil 安装损坏或不完整** 若 Keil 软件本身存在安装问题,比如部分组件丢失或被意外删除,同样会触发上述错误消息[^4]。 #### 解决方案 ##### 方法一:确认并修复设备支持包的安装状态 确保已下载并安装适用于所选微控制器系列的标准设备支持 (Device Support) 包。可以通过访问 Keil 官方网站获取最新版本的支持包,并重新安装以覆盖现有数据。 ##### 方法二:调整项目属性里的 Include Paths 配置项 进入 Project -> Options for Target -> C51 Settings 页面,在 "Include Path" 字段补充上实际存放有 `reg51.h` 头文件的具体目录地址;一般而言,默认应该位于 `<Keil Installation Directory>\C51\INC` 下面。 ##### 方法三:验证当前选用的目标器件是否恰当 双击左侧窗口树形结构下的 Target 名称节点展开其子级菜单列表,检查 Output 和 Debugging 设置里面指定的目标 MCU 类型是不是与正在开发的应用程序相吻合。如果不一致的话,请修改成合适的模型再试一次构建操作。 ##### 方法四:重装 Keil 工具链环境 对于怀疑由于软件自身缺陷引起的情况,建议卸载现有的 Keil 版本之后再次执行干净彻底的新一轮部署过程,期间注意勾选所有关联功能模块以便获得完整的运行支撑框架。 ```c // 示例代码片段展示如何引入 reg51.h 并定义端口寄存器变量 #include <reg51.h> sbit LED = P1^0; // 将P1.0脚映射为LED控制信号位 void main(void){ while(1){ LED=~LED; delay_ms(500); // 模拟延时函数调用实现闪烁效果 } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值