板子
作者:
sher11
,
2024-03-05 14:04:15
,
所有人可见
,
阅读 30
按照给定字典序排序单词(string的读入操作)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
using namespace std;
const int N = 1e5;
string order;
string line;
string arr[N];
int find(char a)
{
for(int i=0;i<order.size();i++)
{
int tmp = abs(a-order[i]);
if(tmp==0||tmp==32) return i;
}
}
bool cmp(string a,string b)
{
for(int i=0;i<min(a.size(),b.size());i++)
{
if(find(a[i])==find(b[i])) continue;
else return find(a[i])<find(b[i]);
}
return a.size()<b.size();
}
int main()
{
while(cin>>order)
{
getchar();
getline(cin,line);
istringstream ss(line);
int n=0;
while(ss>>arr[n]) n++;
sort(arr,arr+n,cmp);
for(int i=0;i<n;i++) cout<<arr[i]<<" ";
puts("");
}
return 0;
}