当前位置:网站首页><Sicily>1000. 数字反转
<Sicily>1000. 数字反转
2022-06-23 12:01:00 【梦飞】
原题如下
1000. 数字反转 Time Limit: 1sec Memory Limit:256MB
Description
给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零(参见样例2)。
Input
输入共 1 行,一个整数N。 -1,000,000,000 ≤ N≤ 1,000,000,000。
Output
输出共 1 行,一个整数,表示反转后的新数。
Sample Input
样例1:
123
样例2:
-380Sample Output
样例1:
321
样例2:
-83思路
其实就是不断把数字的低位放到高位,可以通过不断取余、乘10、除10来完成。
代码
#include <iostream>
using namespace std;
int main(){
int input;
cin >> input;
int output = 0;
int r = input % 10;
while (input != 0){
r = input % 10;
input = input / 10;
output = output * 10 + r;
}
cout << output;
} 边栏推荐
- ROS知识:点云文件.pcd格式
- Meta said that the UK security law may "scan all private information" or infringe privacy
- ROS2知识(6):坐标对象TF原理和实践
- 国产化信息 | 爱可生与中科方德完成产品兼容互认证
- ROS knowledge: the structure of the rviz library librviz
- QT5知识:信号和槽的一些要点
- Halcon principle: one dimensional function_ 1D type [2]
- Common fault analysis and Countermeasures of MySQL in go language
- How to uninstall and reinstall gazebo
- Meta称英安全法可能“扫描所有私人信息” 或侵犯隐私
猜你喜欢

Localization information | aikesheng and China kefangde complete product compatibility and mutual certification

Introduction to redis - Chapter 3 - data structures and objects - Dictionary

Ppt makes 3D rotation animation from beginner to advanced

机器学习系列5:距离空间(1)

公开课丨玩的就是短视频!今晚教你精准变现!

Learning notes sweep crawler framework

Explain the relationship between pyqt5 signal and slot in detail

Redis 入门-第二篇-数据结构与对象-链表

ROS2知识(2):网络设施

ROS知识:点云文件.pcd格式
随机推荐
ROS察微【57】:配置手臂机器人来抓东西
年薪中位数超30万,南大AI专业首届毕业生薪资曝光
WC statistics are out of date, and every line of cloc code is valid
Ros2 knowledge (6): principle and practice of coordinate object TF
2022 construction worker - decoration direction - post skills (construction worker) operation certificate examination question bank simulated examination platform operation
Learning notes sweep crawler framework
I am in Foshan. Where can I open an account? Is it safe to open a mobile account?
Halcon原理:auto_threshold算子
CSS magic nugget mug; Optimization of CK, ES and redisearch schemes in ten million level data query; Why does module circular dependency not lead to dead loop Sauced afternoon tea issue 13
QT5知识:DNS查询
二維激光SLAM( 使用Laser Scan Matcher )
Voice module: pyttsx sound change project
Qt 知识:使用 QGraphicsPixmapItem类
Three ways to learn at work
HMS Core 视频编辑服务开放模板能力,助力用户一键Get同款酷炫视频
Hot spot of equity transfer: 93.75% equity transfer of Chongqing Jianke Construction Engineering Quality Inspection Co., Ltd
QT5知识:信号和槽的一些要点
2022施工员-装饰方向-岗位技能(施工员)操作证考试题库模拟考试平台操作
Introduction to redis - Chapter 1 - data structures and objects - simple dynamic string (SDS)
Qt5 knowledge: QT drawing graph