fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. unsigned int char_classification(const char ch)
  6. {
  7. unsigned int bits_set = 0;
  8. if (iscntrl(ch)) bits_set |= 1U;
  9. if (isprint(ch)) bits_set |= 1U << 1;
  10. if (isspace(ch)) bits_set |= 1U << 2;
  11. if (isblank(ch)) bits_set |= 1U << 3;
  12. if (isgraph(ch)) bits_set |= 1U << 4;
  13. if (ispunct(ch)) bits_set |= 1U << 5;
  14. if (isalnum(ch)) bits_set |= 1U << 6;
  15. if (isalpha(ch)) bits_set |= 1U << 7;
  16. if (isupper(ch)) bits_set |= 1U << 8;
  17. if (islower(ch)) bits_set |= 1U << 9;
  18. if (isdigit(ch)) bits_set |= 1U << 10;
  19. if (isxdigit(ch)) bits_set |= 1U << 11;
  20. return bits_set;
  21. }
  22.  
  23. const std::vector<unsigned int>& string_classification(const std::string& input)
  24. {
  25. const unsigned int n = input.length();
  26. static std::vector<unsigned int> classification(n); //Am I going crazy?
  27.  
  28. for (unsigned int i = 0; i < n; ++i)
  29. classification[i] = char_classification(input[i]);
  30.  
  31. return classification;
  32. }
  33.  
  34. int main()
  35. {
  36. std::string line;
  37. std::getline(std::cin, line);
  38. std::vector<unsigned int> classification{ string_classification(line) };
  39. return 0;
  40. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty