华为机试题练习-求订单人数

计算某一时刻最大订单数。

 

#include 
#include 
#include 
using namespace std;

bool getTimeString(string str1, string str2)
{
    for (string::size_type ix = 0; ix < 20; ++ix)
    {
        if (str1[ix] != str2[ix])
        {
            return false;
        }
            

    }
    return true;
}


int peopleGetCheap(vector vect)
{
    int size = 20;
    int cpc = vect.size();
    vector  sameflag(cpc, true);
    int same = 0;

    unsigned int j = 0;
    for (int i = 0; i < vect.size(); ++i)
    {
        j = i + 1;
        same = 0;
        string str1 = vect[i];
        while (j < vect.size() && sameflag[j])
        {
            string str2 = vect[j];

            if (getTimeString(str1, str2))
            {
                same++;
                sameflag[j] = false;
            }
            j++;
        }

        cpc -= same;
    }
    return cpc;
}



int main()
{
    //string str = "2019-01-01 00:00:00.123";
    //string str = "2019-01-01 00:00:00.001";
    //string str = "2019-01-01 00:00:00.234";
    /*
    2019-01-01 00:00:00.123
    2019-01-02 00:00:00.001
    2019-05-01 00:00:00.234
    2019-05-01 00:00:00.234
    */

    int n;
    int num;
    string str;
    //cin >> n;
    //while (cin >> n)
    //{
    n = 4;
    vector vect;
    for (int j = 0; j < n; ++j)
    {
        //cin >> str;
        getline(cin, str);
        vect.push_back(str);

    }
        num = peopleGetCheap(vect);
        cout << num;
    //}
    return 0;
}

华为机试题练习-求订单人数_第1张图片

 

你可能感兴趣的:(Leetcode)