题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1266
心得:
人人都会做的题,贴个简单点代码,用reverse反转字符串,find_last_not_of('0')返回字符串从后面数第一个不是0的位置。
代码:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int n,minus;
char a[100];
string str;
cin>>n;
while(n--){
cin>>a; str=a;
minus=0;
if(str[0]=='-') minus++;
reverse(str.begin()+minus,str.begin()+str.find_last_not_of('0')+1);
cout<<str<<endl;
}
return 0;
}