91分求助
查看原帖
91分求助
1129659
Kevin626楼主2024/5/1 11:59

做了三天三夜,只有九十一分,我悲痛欲绝。

#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int cnt;
string ss;
stack<char> a;

int main() {
	cin.tie(0);
	getline(cin,ss);
	int len=ss.size();
	string s=ss;
	sort(s.begin(),s.end());
	for(int i=0; i<len; i++) {
		a.push(ss[i]);
		while(!a.empty()&&a.top()==s[cnt]) {
			cout<<a.top();
			a.pop();
			cnt++;
		}
	}
	while(!a.empty()) {
		cout<<a.top();
		a.pop();
	}
	return 0;
}

2024/5/1 11:59
加载中...