Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdexcept>
- constexpr uint64_t operator "" _uniq_hash(char const * str, size_t len) {
- return len > sizeof(uint64_t) / sizeof(char)
- ? throw std::length_error("str")
- : len == 0
- ? 0
- : *str + (operator "" _uniq_hash(str + 1, len - 1) << sizeof(char) * 8);
- }
- uint64_t get_uniq_hash(const std::string& str) {
- if (str.length() > sizeof(uint64_t) / sizeof(char))
- throw std::length_error("str");
- uint64_t result = 0;
- for (auto rit = str.rbegin(); rit != str.rend(); ++rit) {
- result <<= sizeof(char) * 8;
- result += *rit;
- }
- return result;
- }
- int main() {
- using namespace std;
- string word;
- while (cin >> word) {
- if (word.length() < sizeof(uint64_t)) {
- switch (get_uniq_hash(word)) {
- case "zero"_uniq_hash:
- case "one"_uniq_hash:
- case "two"_uniq_hash:
- case "three"_uniq_hash:
- case "four"_uniq_hash:
- case "five"_uniq_hash:
- case "six"_uniq_hash:
- case "seven"_uniq_hash:
- case "eight"_uniq_hash:
- case "nine"_uniq_hash:
- cout << "A number" << endl;
- continue;
- }
- }
- cout << "Not a number" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement