Given a string which is basically a sentence without spaces between words. However the first letter of every word is in uppercase. You need to print this sentence after following amendments:
- Put a single space between these words
- Convert the uppercase letters to lowercase.
Note: The first character of the string can be both uppercase/lowercase.
BruceWayneIsBatman
bruce wayne is batman
class Solution {
public:
string amendSentence (string s)
{
string ans = "";
for(char c: s) {
if(c >= 'A' && c <= 'Z') {
if(ans.size()) {
ans += ' ';
}
ans += (c - 'A' + 'a');
}
else {
ans += c;
}
}
return ans;
}
};