文章

68

粉丝

691

获赞

24

访问

546.5k

头像
题解题解
P1078
发布于2020年5月11日 20:05
阅读数 7.6k

 

代码很简单,用了蛮久的

https://blog.csdn.net/csyifanZhang/article/details/106060687

↑完整题解

 

int main() {
	ll n, p; string s;
	while (cin >> n >> s >> p) {
		string t = s, res;
		sort(t.begin(), t.end());
		p = t.find(s[p - 1]);//p-1号是相同元素中最靠前的
		while (res.size() < n) {
			ll id = -1;
			//s[p]肯定是t中后出现的元素 因为倒推
			for (int j = n - 1; j >= 0; j--)if (t[j] == s[p]) { id = j; break; }
			res += t[id]; t[id] = ' '; p = id;
		}
		reverse(res.begin(), res.end());
		cout << res << endl;
	}
}
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发