Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <string>
  2. #include <cctype>
  3.  
  4. bool is4LettersAnd3Digits(const std::string &s)
  5. {
  6. if (s.length() != 7)
  7. return false;
  8.  
  9. for (int i = 0; i < 4; ++i) {
  10. if (!std::isalpha(s[i]))
  11. return false;
  12. }
  13.  
  14. for (int i = 4; i < 7; ++i) {
  15. if (!std::isdigit(s[i]))
  16. return false;
  17. }
  18.  
  19. return true;
  20. }
  21.  
  22. #include <string>
  23. #include <algorithm>
  24. #include <cctype>
  25.  
  26. bool is4LettersAnd3Digits(const std::string &s)
  27. {
  28. if (s.length() != 7)
  29. return false;
  30.  
  31. if (std::count_if(s.begin(), s.begin()+4, std::isalpha) != 4)
  32. return false;
  33.  
  34. if (std::count_if(s.begin()+4, s.end(), std::isdigit) != 3)
  35. return false;
  36.  
  37. return true;
  38. }
  39.  
  40. #include <string>
  41. #include <algorithm>
  42. #include <cctype>
  43.  
  44. bool is4LettersAnd3Digits(const std::string &s)
  45. {
  46. if (s.length() != 7)
  47. return false;
  48.  
  49. if (!std::all_of(s.begin(), s.begin()+4, std::isalpha))
  50. return false;
  51.  
  52. if (!std::all_of(s.begin()+4, s.end(), std::isdigit))
  53. return false;
  54.  
  55. return true;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement