/*
*什么是字典序最大,例如:
*对于字符串s, x和y是它的子串,x比y大,说明用C语言的字符串比较函数 strcmp(x, y) > 0。
*如 s="ababba", x = "bbba", y="abaa" , x和y都是s的子串,x比y大。
*思路:贪心一点,从后往前找,遇到大的保留,小的去掉,最后倒叙输出即可
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
int j = 0;
char ans[55];
char maxnChar;
cin >> s;
maxnChar = s[s.size()-1];
for (int i=s.size()-1; i>=0; i--) {
if (maxnChar <= s[i]) {
maxnChar = s[i];
ans[j++] = maxnChar;
}
}
for (int i=j-1; i>=0; i--) {
printf ("%c", ans[i]);
}
return 0;
}
最后
以上就是善良身影最近收集整理的关于百度笔试题 最大子序列的全部内容,更多相关百度笔试题内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复