#include <string>
#include <vector>
using namespace std;
string solution(string s) {
string answer = "";
int size = s.size();
int i;
for (i = 0; i < size; i++) {
if (s[i] == ' ') answer += s[i];
else {
if (i == 0 || s[i - 1] == ' ') { // lower -> upper
if ('a' <= s[i] && s[i] <= 'z') answer += (s[i] - 'a' + 'A');
else answer += s[i];
}
else { // upper -> lower
if ('A' <= s[i] && s[i] <= 'Z') answer += (s[i] - 'A' + 'a');
else answer += s[i];
}
}
}
return answer;
}
string solution2(string s) {
string answer = "";
int size = s.size();
int i;
answer += toupper(s[0]);
for (i = 1; i < size; i++) {
s[i - 1] == ' ' ? answer += toupper(s[i]) : answer += tolower(s[i]);
}
return answer;
}