#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;
bool compare(string str1, string str2){
int i = 0;
for(; i < str1.length(); i++){
if(str1[i] >= 49 && str1[i] <= 57){
break;
}
}
string photos1 = str1.substr(0, i);
string temp1 = str1.substr(i, str1.length());
int num1 = atoi(temp1.c_str());
i = 0;
for(; i < str2.length(); i++){
if(str2[i] >= 49 && str2[i] <= 57){
break;
}
}
string photos2 = str2.substr(0, i);
string temp2 = str2.substr(i, str2.length());
int num2 = atoi(temp2.c_str());
if(photos1 < photos2){
return true;
}
else if(photos1 == photos2){
if(num1 < num2){
return true;
}
}
else{
return false;
}
return false;
}
int main()
{
int n;
cin >> n;
int length = n;
string names[100];
while(n){
n--;
string str;
cin >> str;
names[n] = str;
}
sort(names, names+length, compare);
for(int i = 0; i < length; i++){
cout << names[i] << endl;
}
return 0;
}
使用排序函数进行排序,比较大小的方式先将字符切分,再一部分一部分比较。