fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cctype>
  5. #include <vector>
  6. #include <iterator>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. std::vector <std::string> StringVect = { "BB", "-", "", "0", "+", "aA", "12", "b", "AA", "&", "[", "**", "1" };
  12.  
  13. std::sort(StringVect.begin(), StringVect.end(), []
  14. (const std::string& s1, const std::string& s2)
  15. {
  16. if (s1.empty() || s2.empty())
  17. return s1 < s2;
  18.  
  19. bool ac[] = { isalpha(s1[0]), isalpha(s2[0]),
  20. isdigit(s1[0]), isdigit(s2[0]),
  21. !isalnum(s1[0]), !isalnum(s2[0]) };
  22.  
  23. // If both strings start with the same type, then just return the
  24. // lesser one
  25. if ((ac[0] && ac[1]) || (ac[2] && ac[3]) || (ac[4] && ac[5]))
  26. return s1 < s2;
  27. return (ac[0] || ac[5]);
  28. });
  29. copy(StringVect.begin(), StringVect.end(), ostream_iterator<string>(cout, "\n"));
  30. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
AA
BB
aA
b
0
1
12
&
**
+
-
[