#include <iostream>
#include <string>
// Checks if the word is all uppercase, all lowercase, or capitalized
bool verifyAllUpperORAllLowerORIsCapitalized(std::string word) {
int upper = 0;
int lower = 0;
for (auto ch : word) {
if (ch >= 'a' && ch <= 'z') {
lower++;
} else {
if (ch >='A' && ch <= 'Z') {
upper++;
}
}
}
if (upper == 0) return true; // all lowercase
if (lower == 0) return true; // all uppercase
if (upper == 1 && (word[0] >= 'A' && word[0] <= 'Z')) return true; // capitalized
return false;
}
// Runs a test case and prints the result
void runTest(const std::string& word) {
std::cout << "Testing word: \"" << word << "\"\n";
if (verifyAllUpperORAllLowerORIsCapitalized(word)) {
std::cout << "OK\n";
} else if (verifyAllUpperORAllLowerORIsCapitalized(word)) {
std::cout << "OK\n";
} else if (verifyAllUpperORAllLowerORIsCapitalized(word)) {
std::cout << "OK\n";
} else {
std::cout << "Error\n";
}
}
int main() {
runTest("PROGRAMMING");
runTest("programming");
runTest("Programming");
runTest("ProGramMing");
}
/*
run:
Testing word: "PROGRAMMING"
OK
Testing word: "programming"
OK
Testing word: "Programming"
OK
Testing word: "ProGramMing"
Error
*/