Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <cctype>
- bool is4LettersAnd3Digits(const std::string &s)
- {
- if (s.length() != 7)
- return false;
- for (int i = 0; i < 4; ++i) {
- if (!std::isalpha(s[i]))
- return false;
- }
- for (int i = 4; i < 7; ++i) {
- if (!std::isdigit(s[i]))
- return false;
- }
- return true;
- }
- #include <string>
- #include <algorithm>
- #include <cctype>
- bool is4LettersAnd3Digits(const std::string &s)
- {
- if (s.length() != 7)
- return false;
- if (std::count_if(s.begin(), s.begin()+4, std::isalpha) != 4)
- return false;
- if (std::count_if(s.begin()+4, s.end(), std::isdigit) != 3)
- return false;
- return true;
- }
- #include <string>
- #include <algorithm>
- #include <cctype>
- bool is4LettersAnd3Digits(const std::string &s)
- {
- if (s.length() != 7)
- return false;
- if (!std::all_of(s.begin(), s.begin()+4, std::isalpha))
- return false;
- if (!std::all_of(s.begin()+4, s.end(), std::isdigit))
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement