title: Max Repeated Word in a string
body: <p>I was trying to do a very common interview problem "Finding the max repeated word in a string " and could not find much resources in net for c/c++ implementation. So I coded it myself here. 
  I have tried to do most of the coding from scratch for better understanding.
  Could you review my code and provide comments on my algorithm. Some people have suggested using hashtables for storing the count, but am not using hashtables here.</p>
  
  <pre><code>#include&lt;stdafx.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;string&gt;
  #include&lt;iostream&gt;
  using namespace std;
  string word[10];
  
  //splitting string into words
  int parsestr(string str)
  {   
      int index = 0;
      int i = 0;
      int maxlength = str.length();
      int wordcnt = 0;
      while(i &lt; maxlength)
      {
          if(str[i]!= ' ')
          {
              word[index] = word[index]+str[i];
          }
          else
          {
              index++;//new word
              wordcnt = index;
          }
      i++;
      }
      return wordcnt;
  }
  
  //find the max word count out of the array and return the word corresponding to that index.
  string maxrepeatedWord(int wordcntArr[],int count)
  {
  int max = 0;
  int index = 0;
      for(int i=0;i&lt;=count;i++)
      {
          if(wordcntArr[i] &gt; max)
          {
          max = wordcntArr[i];
          index = i;
          }
      }
  
      return word[index];
  }
  void countwords(int count)
  {
      int wordcnt = 0;
      int wordcntArr[10];
      string maxrepeatedword;
      for(int i=0;i&lt;=count ;i++)
      {
          for(int j=0;j&lt;=count;j++)
          {
              if(word[i]==word[j])
              {
              wordcnt++;
              //word[j] = "";
              }
              else
              {}
          }
          cout&lt;&lt;" word "&lt;&lt; word[i] &lt;&lt;" occurs "&lt;&lt; wordcnt &lt;&lt;" times "&lt;&lt;endl;
          wordcntArr[i] = wordcnt;
          wordcnt = 0;
      }
  
      maxrepeatedword = maxrepeatedWord(wordcntArr,count);
      cout&lt;&lt; " Max Repeated Word is " &lt;&lt; maxrepeatedword;
  }
  
  int main()
  {
  string str = "I am am am good good";
  int wordcount = 0;
  wordcount = parsestr(str);
  countwords(wordcount);
  }
  </code></pre>