mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-11-07 07:13:48 +00:00
feat: 实现从输入字符串中提取并排序数字的功能
添加头文件并实现从输入字符串中提取数字字符,按降序排序后输出 跳过前导零以避免无效输出
This commit is contained in:
parent
9c505e630f
commit
712609a466
@ -1,3 +1,32 @@
|
||||
#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";
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user