Find how many inequalities can be simultaneously satisfied Inequality
Given n inequalities about X, how many of them can hold at the same time at most?
The inequalities are in the following forms:

X &lt; C

X &lt;= C

X = C

X &gt; C

X &gt;= C


input

First line with an integer n.

Following n lines, each line with an inequality.

Data Limit:
1 ≤ N ≤ 50, 0 ≤ C ≤ 1000


output

One line with an integer, denoting the answer.

Sample Input
4
X = 1
X = 2
X = 3
X &gt; 0

Sample Output
2


Here is my code:
#include &lt;iostream&gt;
#include &lt;string&gt;

#include &lt;vector&gt;

#include &lt;map&gt;
#include &lt;set&gt;

using namespace std;




int main() {
    //cout&lt;&lt;&quot;请输入:&quot;&lt;&lt;endl;
    int T;
    cin &gt;&gt; T;
    int count = T;
    
    vector&lt;float&gt; arrayOne(T, 0);
    vector&lt;int&gt; arrayTwo(T, 0);
    map&lt;string, int&gt; symbols = {
        pair&lt;string, int&gt;(&quot;&gt;&quot;, 1),
        pair&lt;string, int&gt;(&quot;&gt;=&quot;, 2),
        pair&lt;string, int&gt;(&quot;=&quot;, 3),
        pair&lt;string, int&gt;(&quot;&lt;=&quot;, 4),
        pair&lt;string, int&gt;(&quot;&lt;&quot;, 5)
    };
    
    while(T--)
    {
        string sOne;
        cin &gt;&gt; sOne;
        string sThree;
        cin &gt;&gt; sThree;
        arrayTwo[count-T-1] = symbols.find(sThree)-&gt;second;
        std::string sTwo;
        std::cin &gt;&gt; sTwo;
        float num = stof(sTwo);
        arrayOne[count-T-1] = num;
    }
    set&lt;float&gt; answerSet;
    for (float numPiece: arrayOne){
        answerSet.insert(numPiece-0.5);
        answerSet.insert(numPiece);
        answerSet.insert(numPiece+0.5);
    }
    int answer = 0;
    for (set&lt;float&gt;::iterator testNum=answerSet.begin(); testNum != answerSet.end(); ++testNum){
        //   cout&lt;&lt;*testNum;
        int passNum = 0;
        int i = 0;
        for (int numTwo: arrayTwo){
            switch (numTwo) {
                case 1:
                {
                    if (*testNum &gt; arrayOne[i]) {
                        passNum += 1;
                    }
                }
                    break;
                case 2:
                {
                    if (*testNum &gt;= arrayOne[i]) {
                        passNum += 1;
                    }
                }
                    break;
                case 3:
                {
                    if (*testNum == arrayOne[i]) {
                        passNum += 1;
                    }
                }
                    break;
                case 4:
                {
                    if (*testNum &lt;= arrayOne[i]) {
                        passNum += 1;
                    }
                }
                    break;
                case 5:
                {
                    if (*testNum &lt; arrayOne[i]) {
                        passNum += 1;
                    }
                }
                    break;
                default:
                    break;
            }
            i++;
        }
        answer = max(answer, passNum);
    }
    cout&lt;&lt;answer&lt;&lt;endl;
    return 0;
}

Very intuitive , just get all the boundary numbers, then find the max passes.
How to make it more efficient?
Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is “using namespace std” considered bad practice?.

Don't do everything in main()

Putting all the code into the main() function makes it harder to test parts of the program separately.  If we at least create a function that can read from an arbitrary std::istream, then we're able to do more repeatable testing (by passing suitable std::istringstream objects with our test data in).

Always test that input was successfully read

When we read values from an input stream, we must check that the read was successful before using those values.  A simple way to do that is to set the stream to throw exceptions on failures.

We also need to be more robust when we've read the inequality type, rather than just assuming it will be found in symbols.

Consider using unsigned types

We know that N can't be negative, and the answer is a count of results, which must necessarily be non-negative, too.

Magic numbers

The magic numbers 1..5 used for the different inequalities should be given names.  But there's something better that we can do: we can change their type to be the actual functions:

#include &lt;functional&gt;

///...
{

    using inequality = std::function&lt;bool(float,float)&gt;;

    vector&lt;float&gt; arrayOne(T, 0);
    vector&lt;inequality&gt; arrayTwo(T);
    static const std::map&lt;string, inequality&gt; symbols =
        {
         { "&gt;", std::greater&lt;float&gt;() },
         { "&gt;=", std::greater_equal&lt;float&gt;() },
         { "=", std::equal_to&lt;float&gt;() },
         { "&lt;=", std::less_equal&lt;float&gt;() },
         { "&lt;", std::less&lt;float&gt;() },
        };


Then the big switch becomes much simpler:

    for (auto const&amp; numTwo: arrayTwo){
        passNum += numTwo(*testNum, arrayOne[i]);
        i++;
    }


(I must point out in passing that those names - arrayOne, arrayTwo, numTwo - are really uninformative and unhelpful; you really do need to spend some time thinking of better names if you want to be able to understand your code again later.)

Reconsider the algorithm

Instead of performing all the comparisons on a selection of values (which is O(n²) unless there's many duplicate C values), let's consider what happens to the number of satisfied inequalities as we move X from -∞ to +∞:


each &lt; changes the count by -1 infinitesimally before C
each &lt;= changes the count by -1 infinitesimally after C
&gt;= and &gt; change the count by +1 before or after C, respectively
= changes the count by +1 before and -1 after.


So we can keep an ordered map of those changes:

struct delta
{
    int before;
    int after;

    delta&amp; operator+=(const delta&amp; other)
    {
        before += other.before;
        after  += other.after;
        return *this;
    }
};


Then, just add the appropriate delta values for each inequality:

static const std::map&lt;string, delta&gt; symbol_delta =
    {
     { "&gt;",  {  0,  1 } },
     { "&gt;=", {  1,  0 } },
     { "=",  {  1, -1 } },
     { "&lt;=", {  0, -1 } },
     { "&lt;",  { -1,  0 } },
    };

for (auto i = 0u;  i &lt; lines;  ++i) {
    std::string var;
    std::string symbol;
    double value;

    in &gt;&gt; var &gt;&gt; symbol &gt;&gt; value;
    if (var != "X") {
        throw std::invalid_argument(var);
    }

    auto entry = symbol_delta.find(symbol);
    if (entry == symbol_delta.end()) {
        throw std::invalid_argument(symbol);
    }

    const delta&amp; d = entry-&gt;second;
    changes[value] += d;
    if (d.before + d.after &lt; 0) {
        // it's a less-than relation, so true at -∞
        ++count;
    }
}


When that's done, start with a count of the number of inequalities that are true at -∞, (i.e. the total number of &lt; and &lt;= we've seen) and update that count as we walk the map, keeping track of the maximum:

auto max_count = count;
// now, advance to +∞; updating count as we go
for (auto&amp; entry: changes) {
    const delta&amp; d = entry.second;
    count += d.before;
    if (count &gt; max_count) { max_count = count; }
    count += d.after;
    if (count &gt; max_count) { max_count = count; }
}


The complexity of this algorithm is O(n log n), because we're doing a O(log n) insertion into the map n times.

Full working alternative

#include &lt;istream&gt;
#include &lt;map&gt;
#include &lt;string&gt;

struct delta
{
    int before;
    int after;

    delta&amp; operator+=(const delta&amp; other)
    {
        before += other.before;
        after  += other.after;
        return *this;
    }
};

unsigned int max_inequalities(std::istream&amp; in)
{
    // ensure stream '&gt;&gt;' succeeds or throws
    in.exceptions(std::ios_base::badbit | std::ios_base::failbit);

    unsigned int lines;
    in &gt;&gt; lines;

    std::map&lt;double,delta&gt; changes;
    unsigned int count = 0;     // count of satisfied inequalities at -∞

    static const std::map&lt;std::string, delta&gt; deltas =
        {
         { "&gt;",  {  0,  1 } },
         { "&gt;=", {  1,  0 } },
         { "=",  {  1, -1 } },
         { "&lt;=", {  0, -1 } },
         { "&lt;",  { -1,  0 } },
        };

    for (auto i = 0u;  i &lt; lines;  ++i) {
        std::string var_name;
        std::string comparison;
        double value;

        in &gt;&gt; var_name &gt;&gt; comparison &gt;&gt; value;
        if (var_name != "X") {
            throw std::invalid_argument(var_name);
        }

        auto entry = deltas.find(comparison);
        if (entry == deltas.end()) {
            throw std::invalid_argument(comparison);
        }

        const delta&amp; d = entry-&gt;second;
        changes[value] += d;
        if (d.before + d.after &lt; 0) {
            // it's a less-than relation, so true at -∞
            ++count;
        }
    }

    auto max_count = count;
    // now, advance to +∞; updating count as we go
    for (auto&amp; entry: changes) {
        const delta&amp; d = entry.second;
        count += d.before;
        if (count &gt; max_count) { max_count = count; }
        count += d.after;
        if (count &gt; max_count) { max_count = count; }
    }

    return max_count;
}




#include &lt;iostream&gt;
#include &lt;sstream&gt;

int main()
{
    auto input = std::istringstream{"4\n"
                                    "X = 1\n"
                                    "X = 2\n"
                                    "X = 3\n"
                                    "X &gt; 0\n"
    };

    std::cout &lt;&lt; max_inequalities(input) &lt;&lt; '\n';
}