42 lines
767 B
C++
42 lines
767 B
C++
#include "bob.h"
|
|
|
|
#include <algorithm>
|
|
#include <locale>
|
|
#include <string>
|
|
|
|
namespace bob {
|
|
|
|
|
|
const char * hey(const char input[])
|
|
{
|
|
using namespace std;
|
|
|
|
const string str(input);
|
|
|
|
string::const_reverse_iterator i;
|
|
|
|
i = find_if(str.crbegin(), str.crend(), [](char c){return !isspace(c);});
|
|
|
|
if (i == str.crend())
|
|
return "Fine. Be that way!";
|
|
|
|
bool is_question = *i == '?';
|
|
|
|
i = find_if(i, str.crend(), [](char c){return isalpha(c);});
|
|
|
|
bool has_alpha = i != str.crend();
|
|
|
|
bool is_uppercase = all_of(i, str.crend(),
|
|
[](char c){return isupper(c) || !isalpha(c);});
|
|
|
|
if (has_alpha && is_uppercase)
|
|
return "Whoa, chill out!";
|
|
|
|
if (is_question)
|
|
return "Sure.";
|
|
|
|
return "Whatever.";
|
|
}
|
|
|
|
}
|
|
|