M
M
Mag1str2021-06-13 17:41:27
C++ / C#
Mag1str, 2021-06-13 17:41:27

What data type to use?

It sorts by number normally, and then sorting by letter is needed if the number is the same.
60c633d0ebbde616907578.png
I use char clas[15];

for (int i = 0; i < count; i++)
                for (int j = 0; j < count; j++)
                    if (ob[i].clas[0] < ob[j].clas[0]) {
                        tem = ob[i];
                        ob[i] = ob[j];
                        ob[j] = tem;
                    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wataru, 2021-06-13
@Mag1str

Compare further third characters in strings if the first ones match.
Or compare strings with strcmp.

M
Mag1str, 2021-06-13
@Mag1str

for (int i = 0; i < count; i++)
                    if (ob[i].clas[0] < ob[j].clas[0]) {
                        tem = ob[i];
                        ob[i] = ob[j];
                        ob[j] = tem;
                            for (int i = 0; i < count; i++)
                                if (ob[i].clas[0] < ob[j].clas[0]) {
                                    tem = ob[i];
                                    ob[i] = ob[j];
                                    ob[j] = tem;
                    }
                    }

Y
Yokozuna, 2021-06-15
@Yokozuna

I use the string type to work with strings, you can compare them correctly within the framework of this task:

string a1 = "1-Б";
    string a2 = "1-A";

    if (a1 < a2) {
        // ...
    } else {
       // ...
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question