- P1124 文件压缩
这题很诡异你们知道吗…
#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)
暂无评论