I love competitive programming very much
competitive
void string_q11_longest_word() {
string text = "Find the longest word in this sentence";
string currentWord = "";
string longestWord = "";
for(int i = 0; i <= text.length(); i++) {
if(i < text.length() && text[i] != ' ') {
currentWord += text[i];
} else {
if(currentWord.length() > longestWord.length()) {
longestWord = currentWord;
}
currentWord = "";
}
}
cout << "Sentence: " << text << endl;
cout << "Longest word: " << longestWord << endl;
cout << "Length: " << longestWord.length() << endl;
}
void string_q11_longest_word() {
string text = "Find the longest word in this sentence";
string currentWord = "";
string longestWord = "";
for(int i = 0; i <= text.length(); i++) {
if(i < text.length() && text[i] != ' ') {
currentWord += text[i];
} else {
if(currentWord.length() > longestWord.length()) {
longestWord = currentWord;
}
currentWord = "";
}
}
cout << "Sentence: " << text << endl;
cout << "Longest word: " << longestWord << endl;
cout << "Length: " << longestWord.length() << endl;
}