博客
关于我
NOIP2011T1 数字反转
阅读量:805 次
发布时间: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/

你可能感兴趣的文章
Oracle零碎要点---多表联合查询,收集数据库基本资料
查看>>
Oracle静默安装
查看>>
Oracle面试题:Oracle中truncate和delete的区别
查看>>
ThreadLocal线程内部存储类
查看>>
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>