All pastes #443913 Raw Edit

Stuff

public text v1 · immutable
·published 2007-04-17 02:36 UTC
rendered paste body
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;


int count_words(string sentence) {

	int count=0;
	int poss=0;
	int tmp;

	while (1) {
	
		tmp = sentence.find(" ", poss);

		// if we got end of string return code, then exit loop
		
		if ( tmp == string::npos) 
			break;

		poss += tmp+1;
		
		count++;
	}

	return count;
}





int main() {


	string input; 
	string tmp_string;
	string shortest_sentence="";
	string longest_word="";
	int length=0;
	int poss=0;
	int tmp=0;
	int sentences=0;
	getline(cin, input);


	// count the number of sentences

	while (1) {

		tmp = input.find(".", poss);  

		if (tmp == string::npos)
			break;

		// we have found a sentence, therefore we count it	
		sentences++;

		// copy the string we just extracted into a second string so we can measure it.

		tmp_string = input.substr(poss, tmp);
	
		// check to see if this string is is larger/smaller then our largest/smallest;

		length = count_words(tmp_string);

		// 
		cout << endl << tmp_string << endl << length << "length" << endl;

		poss += tmp+1; // we add one because find returns the first match - aka input[tmp]="." so we want to begin on next char
			       // so we dont count it twice.
	}



	cout << sentences << "sentences" << endl;



}