fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,i;
  6. string s,s1,res;
  7. getline(cin,s);
  8. cin>>n;
  9. for(i=0;i<s.size();i++)
  10. if(s[i]>='0'&&s[i]<='9') s1+=s[i];
  11. stack<char> s2;
  12. for(i=0;i<s1.size();i++)
  13. {
  14. while(!s2.empty()&&s2.top()<s[i]&&(s2.size()-1+s1.size()-i)>=n) s2.pop();
  15. if(s2.size()<n) s2.push(s1[i]);
  16. }
  17. while(!s2.empty())
  18. {
  19. res=s2.top()+res;
  20. s2.pop();
  21. }
  22. cout<<res;
  23. }
  24.  
Success #stdin #stdout 0s 5280KB
stdin
AmN69pQ3e6
2
stdout
36