/// GH solving PPPe-17

#include "..\std_lib_facilities.h"
#include <cstdlib> ///for random numbers
#include <ctime> ///for time()
/****************
17. Write a program that finds the min, max, and mode of a sequence of strings.
********************/

int main() {
    ///enter in a sequence of strings until we're done
    vector<string> svec;
    string temp;
    while(cin >> temp) {
        svec.push_back(temp);
    }
    /// Replace the first character in each string with its lower case value
    /// and remove punctuation
    for(int i = 0; i < svec.size(); ++i) {
        svec[i][0] = tolower(svec[i][0]);
        /// this is where you'd remove punctuation
    }

    ///report out
    cout << "\nYour strings are\n";
    for(int i = 0; i < svec.size(); ++i)
        cout << svec[i] << " ";


    ///copy the vector strings and sort the copy
    vector<string> svec_Copy = svec;
    sort(svec_Copy.begin(),svec_Copy.end());


    ///report out
    cout << "\nThe sorted strings are\n";
    for(int i = 0; i < svec_Copy.size(); ++i) {
        cout << svec_Copy[i] << " ";
    }

    ///Walk through the sorted vector of strings counting the frequencies
    ///and keeping track of the max frequency and what that is
    unsigned frequency, max_frequency=1;
    string mode = svec_Copy[0];
    for(int i = 0; i < svec_Copy.size()-1; ++i) {
        frequency = 1;

        while(svec_Copy[i]==svec_Copy[i+1]) {
            ++frequency;
            ++i;
            cout << "\nsvec_Copy[" << i << "]=" << svec_Copy[i];
            if(i==svec_Copy.size()-1) {
                --i;
                break;
            }
        }
        if(frequency > max_frequency) {
            max_frequency = frequency;
            mode = svec_Copy[i];
        }
    }
    cout << "\nThe min is " << svec_Copy[0]
         << "\nThe max is " << svec_Copy[svec_Copy.size()-1]
         << "\nThe mode is " << mode;
}
