蒟蒻参加不了比赛,那就发篇题解纪念吧。
题目传送门:https://www.luogu.com.cn/problem/P14357
题意:给你一个字符串,取出数字,求这些数字排列之后拼成的最大的数
思路:先输入一个字符串s,遍历字符串中的每一个字符 c ,使用 isdigit 判断这个字符串是否是数字,如果是数字将数字加入到字符串 x 中,最后使用 rbegin 和 rend 对 x 这个字符串进行从大到小排序,最后输出排序之后的字符串。
代码如下
#include<bits/stdc++.h>
using namespace std;
int main() {
string s,x;
cin>>s;
for(char c : s) if(isdigit(c)) x+=c;
sort(x.rbegin(),x.rend());
cout<<x;
return 0;
}