All pastes #415548 Raw Edit

Anonymous

public text v1 · immutable
#415548 ·published 2007-03-29 18:24 UTC
rendered paste body
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  int i;
  int j;
  int size;
  int end;
  int begin;
  int start;
  int lengthWord;
  int counter1;
  int counter2;
  int counter3;
  int counter5;
  int maxindex;
  vector<string>sorting;
  vector<string>smalltogreat;
  string input;
  string temp;

  cout<<"Enter a line of text."<<endl;
  getline(cin, input);
  input = " " + input + " ";
  begin = 0;
  end = 0;
  j=0;
  size=0;

  while(size < input.length())
    {
      while(input[end] == ' ')
	{
	  begin = end;
	  start = begin+1;
	  end++;
	  size++;
	}

      while(input[begin++] != ' ')
	{
	  end = begin;
	  size++;
	}
      
      lengthWord = end - start;
      sorting.resize(j+1);
      sorting.at(j) = input.substr(start, lengthWord);
      j=j+1;
    }

  for(counter1=0; counter1 < (sorting.size()); counter1++)
    {
      cout<<"The words are:"<<sorting.at(counter1)<<endl;
    }

  smalltogreat.resize(sorting.size());

  for(counter3=1; counter3 <= sorting.size(); counter3++)
    {
      for(counter2=0; counter2 < sorting.size(); counter2++)
	{
	  maxindex = 0;
	  if (sorting.at(maxindex) < sorting.at(counter2))
	    maxindex = counter2;
	}
      temp = sorting.at(sorting.size()-1);
      sorting.at(sorting.size()-1) = sorting.at(maxindex);
      sorting.at(maxindex) = temp;

      smalltogreat.at(smalltogreat.size()-counter3) = sorting.at(sorting.size()-1);
      sorting.pop_back();
    }

  for(counter5=0; counter5 < smalltogreat.size(); counter5++)
    {
      if(smalltogreat.at(counter5)==smalltogreat.at(counter5+1))
	cout<<"At least one word appears twice or more in the input."<<endl;
      else
	cout<<"There are no duplicate words in the input."<<endl;
    }

  return 0;
}