fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <string>
  5. #include <cctype>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. string input;
  11. char result[11] {};
  12. int front {0};
  13. int back {9};
  14. bool number_exists {false};
  15.  
  16. cin >> input;
  17.  
  18. for_each(begin(input), begin(input) + 10,
  19. [&](char c) {
  20. if(isdigit(c)) {
  21. if( not number_exists and c != '0' ) {
  22. number_exists = true;
  23. }
  24. result[front++] = c;
  25. } else if(islower(c)) {
  26. result[back--] = c;
  27. }
  28. });
  29.  
  30. if( not number_exists or back == 9 ) {
  31. cout << "error!!" << endl;
  32. return 1;
  33. }
  34.  
  35. sort(begin(result), begin(result) + front, greater<char>());
  36. sort(begin(result) + front, end(result) - 1, less<char>());
  37.  
  38. cout << result << endl;
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3480KB
stdin
g4b208zayx
stdout
8420abgxyz