L1-007. 念数字 C++

本文介绍了一种使用C++编程语言将整数转换为其对应汉字拼音的方法。该程序能够处理包括负数在内的各种整数,并能正确输出每个数字对应的拼音。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址:https://www.patest.cn/contests/gplt/L1-007

题目:

输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出“fu”字。十个数字对应的拼音如下:

0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu

输入格式:

输入在一行中给出一个整数,如: 1234 。

提示:整数包括负数、零和正数。

输出格式:

在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,行末没有最后的空格。如 yi er san si

输入样例:
-600
输出样例:
fu liu ling ling

思路:字符串一顿操作= =数组里有11个字符串,之前一直写成10个,然后找不到错误,然后去换了指针数组,,之后才发现错在哪,但是不想改了2333

代码:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    char *a[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu","fu"};
    char b[11]={'0','1','2','3','4','5','6','7','8','9','-'};
    string shuzi;
    cin>>shuzi;
    int i,j;
    int c=shuzi.length();
    for(i=0;i<c;i++)
    {
        for(j=0;j<11;j++)
        {
            if(shuzi[i]==b[j])cout<<a[j],j=10;
        }
        if(i<c-1)cout<<" ";//这里是很关键的格式问题!
    }
    return 0;
}

root@ubuntu22:~/FPGAs_AdaptiveSoCs_Unified_2024.1_0522_2023# ls api-ms-win-core-console-l1-1-0.dll api-ms-win-core-synch-l1-1-0.dll bin api-ms-win-core-datetime-l1-1-0.dll api-ms-win-core-synch-l1-2-0.dll concrt140.dll api-ms-win-core-debug-l1-1-0.dll api-ms-win-core-sysinfo-l1-1-0.dll data api-ms-win-core-errorhandling-l1-1-0.dll api-ms-win-core-timezone-l1-1-0.dll installLibs.sh api-ms-win-core-file-l1-1-0.dll api-ms-win-core-util-l1-1-0.dll lib api-ms-win-core-file-l1-2-0.dll api-ms-win-crt-conio-l1-1-0.dll msvcp140_1.dll api-ms-win-core-file-l2-1-0.dll api-ms-win-crt-convert-l1-1-0.dll msvcp140_2.dll api-ms-win-core-handle-l1-1-0.dll api-ms-win-crt-environment-l1-1-0.dll msvcp140.dll api-ms-win-core-heap-l1-1-0.dll api-ms-win-crt-filesystem-l1-1-0.dll payload api-ms-win-core-interlocked-l1-1-0.dll api-ms-win-crt-heap-l1-1-0.dll scripts api-ms-win-core-libraryloader-l1-1-0.dll api-ms-win-crt-locale-l1-1-0.dll tps api-ms-win-core-localization-l1-2-0.dll api-ms-win-crt-math-l1-1-0.dll ucrtbase.dll api-ms-win-core-memory-l1-1-0.dll api-ms-win-crt-multibyte-l1-1-0.dll vccorlib140.dll api-ms-win-core-namedpipe-l1-1-0.dll api-ms-win-crt-private-l1-1-0.dll vcruntime140_1.dll api-ms-win-core-processenvironment-l1-1-0.dll api-ms-win-crt-process-l1-1-0.dll vcruntime140.dll api-ms-win-core-processthreads-l1-1-0.dll api-ms-win-crt-runtime-l1-1-0.dll xsetup api-ms-win-core-processthreads-l1-1-1.dll api-ms-win-crt-stdio-l1-1-0.dll xsetup.exe api-ms-win-core-profile-l1-1-0.dll api-ms-win-crt-string-l1-1-0.dll xsetup.exe.manifest api-ms-win-core-rtlsupport-l1-1-0.dll api-ms-win-crt-time-l1-1-0.dll api-ms-win-core-string-l1-1-0.dll api-ms-win-crt-utility-l1-1-0.dll 这是linux版本还是windows版本
最新发布
07-19
要判断一个文件列表中的文件是属于 Linux 还是 Windows 系统版本,可以从文件路径的格式、文件扩展名以及文件内容等多个方面进行分析。 ### 1. 文件路径格式 - **Windows 路径**:通常使用反斜杠 `\` 作为路径分隔符,例如 `C:\Program Files\Example\file.txt`。在某些情况下,路径可能以盘符开头(如 `C:`、`D:`)。 - **Linux 路径**:通常使用正斜杠 `/` 作为路径分隔符,例如 `/home/user/example/file.txt`。Linux 路径通常以根目录 `/` 开头,且没有盘符的概。 可以通过检查路径中的分隔符来判断系统类型。例如,如果路径中包含 `\`,则可能是 Windows 系统;如果路径中包含 `/`,则可能是 Linux 系统。这种方法虽然不是绝对可靠,但在大多数情况下可以提供一定的线索。 ```python import os def detect_os_from_path(path): if '\\' in path: return 'Windows' elif '/' in path: return 'Linux' else: return 'Unknown' ``` ### 2. 文件扩展名 - **Windows 文件**:常见的可执行文件扩展名为 `.exe`、`.dll` 等。 - **Linux 文件**:可执行文件通常没有特定的扩展名,但脚本文件可能以 `.sh` 结尾,而动态库文件通常以 `.so` 结尾。 通过检查文件的扩展名,可以推测该文件是否为特定平台的可执行文件或库文件。例如,如果文件以 `.exe` 结尾,则很可能是 Windows 可执行文件;如果文件以 `.so` 结尾,则很可能是 Linux 动态库文件。 ### 3. 文件内容分析 对于某些文件类型,仅凭文件路径和扩展名可能无法准确判断其所属的操作系统。此时可以通过分析文件内容来进一步确认。 - **ELF 文件**:Linux 系统上的可执行文件和共享库通常是 ELF(Executable and Linkable Format)格式。可以通过检查文件的魔数(magic number)来判断是否为 ELF 文件。ELF 文件的魔数为 `7F 45 4C 46`(即 ASCII 中的 `\x7fELF`)。 ```python def is_elf_file(file_path): try: with open(file_path, 'rb') as f: magic = f.read(4) return magic == b'\x7fELF' except Exception: return False ``` - **PE 文件**:Windows 系统上的可执行文件通常是 PE(Portable Executable)格式。PE 文件的魔数为 `4D 5A`(即 ASCII 中的 `MZ`),并且在文件偏移 0x3C 处有一个指向 PE 头的指针。 ```python def is_pe_file(file_path): try: with open(file_path, 'rb') as f: magic = f.read(2) if magic != b'MZ': return False f.seek(0x3C) pe_offset = int.from_bytes(f.read(4), byteorder='little') f.seek(pe_offset) pe_magic = f.read(4) return pe_magic == b'PE\x00\x00' except Exception: return False ``` ### 4. 文件属性和元数据 在某些情况下,文件的元数据也可以提供线索。例如,在 Linux 系统中,文件的权限信息、所有者和组等信息可以通过 `ls -l` 命令查看;而在 Windows 系统中,文件的属性可以通过 `dir` 命令查看。此外,文件的时间戳格式也可能有所不同。 ### 5. 工具辅助分析 除了手动分析外,还可以使用一些工具来帮助判断文件所属的操作系统。例如: - **file 命令**(Linux):可以用来识别文件的类型,包括是否为 ELF 或 PE 文件。 - **Dependency Walker**(Windows):可以用来分析 Windows 可执行文件的依赖关系,帮助判断文件是否为 Windows 平台的可执行文件。 ###
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值