boxmoe_header_banner_img

Hello! 欢迎DRheEheAM的blog!

加载中

文章导读

Oct. 4th 日常做题总结


avatar
DRheEheAM_Gary 2025-10-04 193

这题很诡异你们知道吗…

#include<bits/stdc++.h>
using namespace std;
#define intc const int
#define intl long long
#define Cios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
intc N=1e4+10;
int n,p;
bool b[N];
string s1,s2;
pair<char,char> s[N];
stack<char> st;
signed main(){
	cin>>n;
	cin>>s1;
	cin>>p;
	s2=s1;
	sort(s2.begin(),s2.end());
	for (int i=0;i<n;i++) s[i+1]=make_pair(s2[i],s1[i]);
	int now=-1,pto=-1;
	for (int i=1;i<=n;i++) {
		if (!b[i]&&s[i].first==s[p].second) {
			now=i;
			pto=i;
			b[i]=1;
			st.push(s[i].second);
			break;
		}
	}
	do {
		bool ok=1;
		for (int i=1;i<=n;i++) {
			if (!b[i]&&s[i].first==s[now].second) {
				ok=0;
				now=i;
				b[i]=1;
				st.push(s[i].second);
				break;
			}
		}
		if (ok) break;
	} while (now!=pto);
	while (st.size()) {
		cout<<st.top();
		st.pop();
	}
	return 0;
}


评论(0)

查看评论列表

暂无评论


发表评论

表情 颜文字
插入代码
DRheEheAM_Gary Blog