feat: 实现从输入字符串中提取并排序数字的功能

添加头文件并实现从输入字符串中提取数字字符,按降序排序后输出
跳过前导零以避免无效输出
This commit is contained in:
Zengtudor 2025-11-06 21:16:12 +08:00
parent 9c505e630f
commit 712609a466

View File

@ -1,3 +1,32 @@
int main(){
#include <algorithm>
#include <cctype>
#include <functional>
#include <iostream>
#include <istream>
#include <string>
#include <vector>
using ll = int64_t;
std::string s;
std::vector<char> v;
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin>>s;
v.reserve(s.size());
for(char c:s){
if(isdigit(c)){
v.emplace_back(c);
}
}
std::sort(v.begin(),v.end(),std::greater<>());
bool isf=true;
for(char c:v){
if(isf&&c=='0')continue;
isf=false;
std::cout<<c;
}
std::cout<<"\n";
}