题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1266
思路:特判0就行
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long ll;
const int maxn = 40000;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int a[20];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
bool flag = false;
scanf("%d",&n);
if(n == 0)
{
printf("0\n");
continue;
}
if(n < 0)
{
flag = true;
n = -n;
}
int k = 0;
while(n)
{
a[k++] = n % 10;
n /= 10;
}
int sum = 0,cf;
for(int i=0; i<k; i++)
{
if(a[i] == 0)
sum++;
else
{
cf = i;
break;
}
}
if(flag)
printf("-");
for(int i=cf; i<k; i++)
{
printf("%d",a[i]);
}
for(int i=1; i<=sum; i++)
printf("0");
printf("\n");
}
return 0;
}
AC代码:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int n,i;
string s;
cin>>n;
while(n--)
{
cin>>s;
for(i=s.length()-1; i>=0; i--)
if(s[i] != '0')
break;
if(s[0] == '-')
reverse(s.begin()+1,s.begin()+i+1);
else
reverse(s.begin(),s.begin()+i+1);
cout<<s<<endl;
}
return 0;
}