【ybtoj 高效进阶 2.1】【字符串】 数字翻转

【ybtoj 高效进阶 2.1】【字符串】 数字翻转

题目

在这里插入图片描述


解题思路

用字符串输入
倒着重组出一个数
注意负号


代码

#include<cstdio>
using namespace std;
int x,y;
string s;
int main()
{
    
    
	cin>>s;
	if (s[0]=='-') printf("-"),x++;
	for (int i=s.size()-1;i>=x;i--)
	    y=y*10+s[i]-48;
	printf("%d\n",y);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45621109/article/details/113029889