<commit_before>// 4.exercise.17.cpp
//
// Write a program that finds the min, max and the mode of a sequence of
// strings.

#include "std_lib_facilities.h"

int main()
{
    vector<int> sample;

    cout << "Write a series of integer numbers (end the input with Ctrl+D): ";
    int element {0};
    while (cin >> element)
        sample.push_back(element);

    if (sample.size() != 0) {
        // Vector to store different values from sample
        vector<int> values;
        // Vector to store the times each element from values appears in sample
        vector<int> times;
        
        // A sort sample simplifies the problem
        sort(sample);
        // First element in sample
        values.push_back(sample[0]);
        times.push_back(1);
        // Get every unique element and the times ir appears in sample
        for (size_t i=1; i<sample.size(); ++i) {
            if (sample[i] == sample[i-1]) {
                ++times[times.size()-1];
            } else {
                values.push_back(sample[i]);
                times.push_back(1);
            }
        }

        // Time to get the max in times
        // What if there are more than a mode (various elements that appers
        // the same amount of times, and that amount is the maximum)? I think
        // that we still don't know enough to solve that situation in
        // an efficent way.
        int max {0};
        int idx {0};
        for (size_t i=0; i<times.size(); ++i) {
            if (times[i] > max) {
                max = times[i];
                idx = i;
            }
        }

        cout << "The mode of the sample is " << values[idx] << " with " 
            << times[idx] << " appareances.\n";

    } else {
        cout << "No data introduced.\n";
    }

    return 0;
}

<commit_msg>Chapter 4, exercise 17, finished<commit_after>// 4.exercise.17.cpp
//
// Write a program that finds the min, max and the mode of a sequence of
// strings.

#include "std_lib_facilities.h"

int main()
{
    vector<string> sample;

    cout << "Write a series of strings (end the input with Ctrl+D): ";
    string element {""};
    while (cin >> element)
        sample.push_back(element);

    if (sample.size() != 0) {
        // Vector to store different values from sample
        vector<string> values;
        // Vector to store the times each element from values appears in sample
        vector<int> times;
        
        // A sort sample simplifies the problem
        sort(sample);
        // First element in sample
        values.push_back(sample[0]);
        times.push_back(1);
        // Get every unique element and the times ir appears in sample
        for (size_t i=1; i<sample.size(); ++i) {
            if (sample[i] == sample[i-1]) {
                ++times[times.size()-1];
            } else {
                values.push_back(sample[i]);
                times.push_back(1);
            }
        }

        // min nad max
        string min {sample[0]};
        string max {sample[0]};
        for ( string s : sample ) {
            if ( s < min ) min = s;
            if ( s > max ) max = s;
        }
        // Time to get the max in times
        // What if there are more than a mode (various elements that appers
        // the same amount of times, and that amount is the maximum)? I think
        // that we still don't know enough to solve that situation in
        // an efficent way.
        int max_times {0};
        int idx {0};
        for (size_t i=0; i<times.size(); ++i) {
            if (times[i] > max_times) {
                max_times = times[i];
                idx = i;
            }
        }

        cout << "The min string in the sample is: " << min << '\n';
        cout << "The max string in the sample is: " << max << '\n';
        cout << "The mode of the sample is " << values[idx] << " with " 
            << times[idx] << " appareances.\n";

    } else {
        cout << "No data introduced.\n";
    }

    return 0;
}


{'fraction_non_alphanumeric': 0.12029131089904571, 'fraction_numerical': 0.008538422903063787, 'mean_word_length': 1.6394963552021207, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2448518', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1134, 'n_words': 419}