Determine sentence type: Difference between revisions

Content added Content deleted
(New post.)
m (Minor code improvement.)
Line 169: Line 169:
#include <vector>
#include <vector>


char sentence_type(std::string sentence) {
char sentence_type(const std::string& sentence) {
if ( sentence.empty() ) {
if ( sentence.empty() ) {
throw std::invalid_argument("Cannot classify an empty sentence");
throw std::invalid_argument("Cannot classify an empty sentence");
Line 191: Line 191:
"Just make sure you don't break it" };
"Just make sure you don't break it" };


for ( std::string sentence : sentences ) {
for ( const std::string& sentence : sentences ) {
std::cout << sentence << " -> " << sentence_type(sentence) << std::endl;
std::cout << sentence << " -> " << sentence_type(sentence) << std::endl;
}
}