提供一个思路,用字符串不会超时

csp-s毁了我的梦  •  1年前


include<bits/stdc++.h>

using namespace std; int main() {

string a;
cin>>a;
int l=a.size();
int l1=a.size();
if(a[0]=='-') {
	cout<<"-";
	for(string::reverse_iterator rit=a.rbegin(); rit!=a.rend()-1 ; rit++) {
		if(*rit=='0'&&l==l1) {
			l--;
			l1--;
			continue;
		} else {
			cout<<*rit;
			l--;
		}
	}
} else {
	for(string::reverse_iterator rit=a.rbegin(); rit!=a.rend() ; rit++) {
		if(*rit=='0'&&l==l1) {
			l--;
			l1--;
			continue;
		} else {
			cout<<*rit;
			l--;
		}
	}
}
return 0;

}


评论:

请先登录,才能进行评论