Сортировка по первой числовой цифре, а затем по первому алфавитному символу.Не делает никаких предположений, где первая числовая цифра и первый алфавитный символ расположены в строках (если они существуют).Но предполагается, что все числа имеют одинаковое количество цифр.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> vec{"202 Physics","101 Math","303 Chemistry"};
cout << "Original\n";
for (auto item : vec)
std::cout << item << " ";
cout << std::endl;
cout << "Sort by first digit\n";
std::sort(std::begin(vec ), std::end(vec ), [](string a, string b)
{return *find_if(a.begin(), a.end(), [](char c){return isdigit(c);})
< *find_if(b.begin(), b.end(), [](char c){return isdigit(c);}); });
for (auto item : vec)
std::cout << item << " ";
cout << std::endl;
cout << "Sort by first alphabetical char\n";
std::sort(std::begin(vec ), std::end(vec ), [](string a, string b)
{return *find_if(a.begin(), a.end(), [](char c){return isalpha(c);})
< *find_if(b.begin(), b.end(), [](char c){return isalpha(c);}); });
for (auto item : vec)
std::cout << item << " ";
cout << std::endl;
}
Выводит:
Original
202 Physics 101 Math 303 Chemistry
Sort by first digit
101 Math 202 Physics 303 Chemistry
Sort by first alphabetical char
303 Chemistry 101 Math 202 Physics