博客
关于我
NOIP2011T1 数字反转
阅读量:806 次
发布时间:2023-02-16

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

n, m, c: longint;begin    assign(input, 'reverse.in');    reset(input);    assign(output, 'reverse.out');    rewrite(output);    readln(n);    if n < 0 then        begin            n := -n;            write('-');        end;    m := 0;    while n > 0 do    begin        m := m * 10 + n mod 10;        n := n div 10;    end;    writeln(m);    close(input);    close(output);end.

这段代码实现了将一个数字反转的功能。具体来说,它首先读取一个整数n,如果n是负数,则添加一个负号。然后通过循环逐步将n的每一位数字提取出来,并按相反顺序组合成一个新的数字m。循环结束后,m的值即为n的反转数。这个过程不需要额外的空间复杂度,仅使用了一个额外的变量m来存储中间结果。

转载地址:http://sojfk.baihongyu.com/

你可能感兴趣的文章
PIESDKDoNet二次开发配置注意事项
查看>>
PIGS POJ 1149 网络流
查看>>
PIL Image对图像进行点乘,加上常数(等像素操作)
查看>>
PIL Image转Pytorch Tensor
查看>>
PIL&QOOT;IOERROR:带有大图像的图像文件被截断(&Q)
查看>>
PIL.Image、cv2的img、bytes相互转换
查看>>
PIL.Image进行图像融合显示(Image.blend)
查看>>
pilicat-dfs 霹雳猫-分布式文件系统
查看>>
Pillow lacks the JPEG 2000 plugin
查看>>
SpringBoot之ElasticsearchRestTemplate常用示例
查看>>
ping 全网段CMD命令
查看>>
ping 命令的七种用法,看完瞬间成大神
查看>>
Pinia入门(快速上手)
查看>>
Pinia:$patch的使用场景
查看>>
Pinia:$subscribe()的使用场景
查看>>
Pinpoint对Kubernetes关键业务模块进行全链路监控
查看>>
Pinterest 大规模缓存集群的架构剖析
查看>>
pintos project (2) Project 1 Thread -Mission 1 Code
查看>>
PinYin4j库的使用
查看>>
PIP
查看>>