# 2896. 随机排序

wa了一个小时

### include

int p[26];
int cmp(const void a,const void b)
{
char s1,s2;char ch1,ch2;
s1=(char )a;s2=(char )b;
while(s1&&s2)
{
ch1=(s1)>=’a’?s1-32:s1; //转换为大写字母
ch2=(
s2)>=’a’?s2-32:s2; //转换为大写字母
if(p[ch1-‘A’]!=p[ch2-‘A’]) //按字母顺序表比较字母
return p[ch1-‘A’]-p[ch2-‘A’];
else {s1++;s2++;}
}
if(*s1==0) return -1;
else return 1;
}

int main()
{
char s[27];
int i,j,count;
while(scanf(“%s\n”,s)!=EOF)
{
for(i=0; i<26; i++)
p[s[i]-‘A’]=i;
char str[2200];
char a[100][50];
gets(str);
count=0; i=0;
while(1)
{ j=0;
while(str[i]!=’ ‘&&str[i])
{
a[count][j++]=str[i++];
}
a[count][j]=’\0’;
count++;
if(!str[i]) break; else i++;
}

qsort(a,count,sizeof(a[0]),cmp);

for(i=0; i<count-1; i++)
printf("%s ",a[i]);
printf("%s\n",a[i]);
}


}

#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;
const int maxn = 1e5+5;

string arr[maxn];
string order;

bool cmp(string a,string b){
for (int i = 0; i < min(a.length(),b.length()); ++i) {
char t1 = toupper(a[i]);
char t2 = toupper(b[i]);
if (order.find(t1) == order.find(t2)) continue;
return order.find(t1) < order.find(t2);
}
return a.length()<b.length();
}

int main() {
string temp;
while(cin>>order){
getchar();
getline(cin,temp);
istringstream ss(temp);
int n=0;
while(ss >> arr[n]){
n++;
}
sort(arr,arr+n,cmp);
for (int i = 0; i < n; ++i) {
cout<<arr[i];
if (i!=n-1) cout<<" ";
else cout<<endl;
}
}
return 0;
}


#include "bits/stdc++.h"
using namespace std;

int main() {
for (string order; cin >> order;) {
unordered_map<char, char> weight;
for (char i = 0, sz = (char)order.size(); i != sz; ++i) {
weight.insert({ order[i], i });
}
cin.get();
string text;
getline(cin, text);
istringstream in(text);
struct Rec {
string text;
string sort_key;
};
vector<Rec> strs;
for (Rec temp; in >> temp.text;) {
uint32_t sz = (uint32_t)temp.text.size();
temp.sort_key.resize(sz);
for (uint32_t i = 0; i < sz; ++i) {
temp.sort_key[i] = weight.at((char)toupper(temp.text[i]));
}
strs.push_back(move(temp));
}
sort(strs.begin(), strs.end(), [](auto const& a, auto const& b) {
return a.sort_key < b.sort_key;
});
printf("%s", strs.front().text.data());
for (uint32_t i = 1, sz = (uint32_t)strs.size(); i != sz; ++i) {
// safely assume sz >= 1;
printf(" %s", strs[i].text.data());
}
putchar('\n');
}
}


fire firefox

IN:***
f fff ff ffff
OUT必须是f ff fff ffff

fire firefox
\0和f比？题目没说清楚！？？
[em:07][em:07]

while True:
try:
dic={}
def mycmp(s):
res=0
p=-1
s=s.upper()
for c in s:
res+=dic[c]*p
p/=100
return res
pri=input()
for i,c in enumerate(pri):
dic[c]=i+1
letters=list(input().split())
letters.sort(key=mycmp, reverse=True)
print(” “.join(letters))
except:
break