1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <cctype>
#include <map>
auto Rand {std::mt19937 {std::random_device {}()}};
enum userResponse:unsigned { error0 = 0, yes, no, error3 };
std::string getExp()
{
static const std::vector<std::string> resVec {
"Huh? I'm not sure I understand...",
"Lol. I have no idea what you mean",
"say whaaaaa?",
"Um, I dunno what that means",
"Can you repeat that?",
"I honestly have no idea how to respond to that",
"you're cracking me up. I don't know what I'm supposed to say to that",
"come on, seriously",
"lol. not sure i understood you...",
"lol. I can also say stuff that doesn't make any sense!",
"I'm not stupid. I just have no idea what you're trying to tell me",
"come again?",
"Umm...\nthat makes just as much sense to me as biology does...",
"Is that code for something?",
"I have a feeling that you might be messing with me",
"Umm, what???"
};
static auto randNo {std::uniform_int_distribution<size_t> {0, resVec.size() - 1}};
return resVec[randNo(Rand)];
}
userResponse checkUserResponse(std::string userInput)
{
struct classcomp {
bool operator() (const std::string& lhs, const std::string& rhs) const
{
return lhs.size() > rhs.size();
}
};
static const std::multimap<std::string, userResponse, classcomp> res {
{"yes", yes},
{"ya", yes},
{"yeah", yes},
{"yea", yes},
{"yep", yes},
{"yup", yes},
{"ok", yes},
{"okay", yes},
{"sure", yes},
{"why not", yes},
{"fine", yes},
{"no", no},
{"nope", no},
{"na", no},
{"naa", no},
{"i'm good", no},
{"not really", no},
{"i'm ok", no},
{"i'm okay", no},
{"i'd rather not", no},
{"i would rather not", no}
};
std::transform(userInput.begin(), userInput.end(), userInput.begin(), [](auto ch) {return (char)std::tolower(ch); });
unsigned checkedResult {error0};
for (const auto& [word, typ] : res)
for (size_t f = 0; (f = userInput.find(word, f)) != std::string::npos; ++f)
if ((f == 0 || std::isspace(userInput[f - 1])) && (f + word.size() >= userInput.size() || std::isspace(userInput[f + std::size(word)]))) {
checkedResult |= typ;
userInput.erase(f, word.size());
f = 0;
}
return (userResponse)checkedResult;
}
int main()
{
std::string reply;
std::cout << "Enter reply: ";
std::getline(std::cin, reply);
switch (checkUserResponse(reply)) {
case yes:
std::cout << "Yes\n";
break;
case no:
std::cout << "No\n";
break;
default:
std::cout << getExp() << '\n';
break;
}
}
|