博客
关于我
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/

你可能感兴趣的文章
POJ 2391 多源多汇拆点最大流 +flody+二分答案
查看>>
POJ 2403
查看>>
poj 2406 还是KMP的简单应用
查看>>
POJ 2431 Expedition 优先队列
查看>>
Qt笔记——获取位置信息的相关函数
查看>>
POJ 2484 A Funny Game(神题!)
查看>>
POJ 2486 树形dp
查看>>
POJ 2488:A Knight&#39;s Journey
查看>>
SpringBoot为什么易学难精?
查看>>
poj 2545 Hamming Problem
查看>>
poj 2723
查看>>
poj 2763 Housewife Wind
查看>>
Qt笔记——模型/视图MVD 文件目录浏览器软件
查看>>
POJ 2892 Tunnel Warfare(树状数组+二分)
查看>>
poj 2965 The Pilots Brothers' refrigerator-1
查看>>
poj 3026( Borg Maze BFS + Prim)
查看>>
POJ 3041 - 最大二分匹配
查看>>
POJ 3041 Asteroids(二分匹配模板题)
查看>>
Qt笔记——标准文件对话框QFileDialog
查看>>
poj 3083 Children of the Candy Corn
查看>>