贪心WA一个点但每次WA的点不一样
查看原帖
贪心WA一个点但每次WA的点不一样
565707
mediocre_楼主2023/7/17 10:05
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int first = -1, last = -1;
	for (int i = 0; i < s.length(); ++i)
		if (s[i] == '1') {
			first = i;
			break;
		}
	for (int i = s.length() - 1; i >= 0; --i)
	    if (s[i] == '0') {
	    	last = i;
	    	break;
		}
	if (first != -1 && last != -1) {
		for (int i = first, j = last; i <= j, j >= i; ++i, --j)
			swap(s[i], s[j]);
	}
	for (int i = 0; i < s.length(); ++i)
	    cout<<s[i];
	return 0;
}
2023/7/17 10:05
加载中...