注解
1、字符串处理,仔细理解题目,分为:末尾带0,末尾不带0,以及正数和负数的情况。
2、特别注意:输入0的时候,输出0,一定不能错。否则会报WA。
代码
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
for(int i=0; i<n; i++) {
string s;
cin>>s;
if(!s.compare("0")) {
cout<<s<<endl;
} else {
int pos = s.length()-1;
while(s.at(pos)=='0') {
pos--;
}
string s2;
if(s.at(0)=='-') {
s2 += "-";
for(int j=pos; j>=1; j--) {
s2 += s.at(j);
}
} else {
for(int j=pos; j>=0; j--) {
s2 += s.at(j);
}
}
for(int j=pos+1; j<s.length(); j++) {
s2 += s.at(j);
}
cout<<s2<<endl;
}
}
return 0;
}