题目:数字反转。给你一个整数,反转得到新数,要求考虑正负号,最高位不为0.
例如:123得到321
-860得到-68
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char s[100000005];
int a=1,t=0;
scanf("%s",s);
if(s[0]=='-')
putchar(s[0]);
else
a=0;
for(int i=strlen(s)-1;i>=a;i--)
{
if(s[i]=='0'&&t==0)
continue;
if(s[i]!='0')
t=1;
putchar(s[i]);
}
return 0;
}
注意:a,t的使用技巧;
倒序输出的方法
strlen(字符数组),用于对char类型的使用
字符串.length,用于对string类型的使用