// Extract longest and shortest word from a stream of text.
// Version 1.0
// Date 11:03 08/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
#include <vector>

using namespace std;
using std::cout;
using std::endl;

int main(int argc, char *argv[]){
	string sText = "We had the best walk in the park today the weather was fantastic";
	string sWord = "";
	int i = 0;
	int max = 0;
	int min = 0;
	int max_idx = 0;
	int min_idx = 0;
	vector<string>words;

	//Source text
	cout << "Source: " << endl << sText.c_str() << endl << endl;

	//Append last space so we can get the last word.
	if (!sText[sText.length()-1]!='\ '){
		sText += " ";
	}

	//Split the words into a vector.
	while (i < sText.length()){
		if (sText[i] == '\ '){
			//Add to vector
			words.push_back(sWord);
			sWord.clear();
		}
		else{
			sWord += sText[i];
		}
		i++;
	}

	i = 0;
	min = words[0].length();

	while (i < words.size()){
		sWord = words[i];
		//Find the lonest word.
		if (sWord.length() > max){
			max_idx = i;
			max = sWord.length();
		}
		//Find the shortest word.
		if (sWord.length() < min){
			min_idx = i;
			min = sWord.length();
		}
		i++;
	}

	//Print out info.
	cout << "Longest  word : " << words[max_idx].c_str() << endl;
	cout << "Shortest word : " << words[min_idx].c_str() << endl;

	//Clear up.
	words.clear();

	system("pause");
	return 0;
}