# 3055. 字符频率

#include<iostream>
#include<string>
#include<algorithm>
#include <cstring>
using namespace std;
typedef struct item {
double frequency;
int alphabet;
item() {}
item(int f, int a) :frequency(f), alphabet(a) {}
}item;

item current[26];
bool cmp(item A, item B) {
return A.frequency > B.frequency;
}

int table[300]; // 往大了开

int main() {
int times;
scanf("%d", &times);
for (int k = 0; k < times; k++) {
memset(table, 0, sizeof(table));
for (int j = 0; j < 26; j++) {
scanf("%lf", &current[j].frequency);
current[j].alphabet = j + 'a';
}
//将频率和字符的对应 写为整体存到数组中;

//从 current的首地址开始,按照freq的从大到小排列
sort(current, current + 26, cmp);
string str;
cin >> str;
//    标记出元素是否存在
for (auto i = 0u; i < str.size(); i++) { // 遍历的是字符串
table[str[i]] ++;
}
//按照频率进行输出
printf("case #%d:\n", k);
for (auto i = 'a'; i <= 'z'; i++) { //这种写法避免错误
//如果排序结构体的 前面i个 存在. 则输出
if (table[current[i - 'a'].alphabet] > 0 || table[current[i - 'a'].alphabet - 'a' + 'A'] > 0) {
while (table[current[i - 'a'].alphabet] > 0) {
table[current[i - 'a'].alphabet]--;
printf("%c", current[i - 'a'].alphabet);
}
while (table[current[i - 'a'].alphabet - 'a' + 'A'] > 0) {
table[current[i - 'a'].alphabet - 'a' + 'A']--;
printf("%c", current[i - 'a'].alphabet - 'a' + 'A');
}
}
}
printf("\n");
}

}


### include

int noe(char s)
{
if(s>=’A’&&s<=’Z’) return s+32;
else return s;
}
int main()
{
int n,i;
int noe(char s);
scanf(“%d”,&n);
for(i=0;i<n;i++){
int k,m,n;
double num[26];
for(k=0;k<26;k++){
scanf(“%lf”,&num[k]);
}
char str[100],tmp;
scanf(“%s”,str);
for(m=0;m<strlen(str)-1;m++){
for(k=0;k<strlen(str)-1-m;k++){
if(num[noe(str[k])-‘a’]<=num[noe(str[k+1])-‘a’]){
tmp=str[k];
str[k]=str[k+1];
str[k+1]=tmp;
}
if(noe(str[k])==noe(str[k+1])&&str[k]<str[k+1]){
tmp=str[k];
str[k]=str[k+1];
str[k+1]=tmp;
}
}
}
for(m=0;m<strlen(str)-1;m++){
for(k=0;knoe(str[k+1])){
tmp=str[k];
str[k]=str[k+1];
str[k+1]=tmp;
}
}
}
printf(“case #%d:\n”,i);
printf(“%s\n”,str);
}
return 0;
}

# include

### include

using namespace std;
double num[30]={};
struct hello{
double p;
char x,y;
};

bool cmp(hello a,hello b){
if(a.p!=b.p)return a.p>b.p;
else if(a.x!=b.x)return a.xb.y;
}
int main(){
int n,i,j,k;
string str;
cin>>n;
for(i=0;i<n;i++){
hello g[110]={};
for(j=0;j<26;j++){
cin>>num[j];
}
cin>>str;
for(j=0;j=’a’&&str[j]<=’z’){
g[j].x=g[j].x+’A’-‘a’;
}
len=g[j].x-‘A’;
g[j].p=num[len];
}
sort(g,g+j,cmp);
cout<<”case #”<<i<<”:”<<endl;
for(k=0;k<j;k++){
cout<<g[k].y;
}
cout<<endl;
}
}

### include

using namespace std;
int T;
char line[110];
double f[26];
int cmp(const char& aa,const char& bb)
{
if(tolower(aa)==tolower(bb)) return aa>bb; //同一个字母，小写asc码大，排前面
}
void solve()
{
for(int i=0;i<26;i++) cin>>f[i];
scanf(“%s”,line);
int ll=strlen(line);
sort(line,line+ll,cmp);
cout<<line<<endl;
return;
}
int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}

#include <cstring>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <tuple>

using namespace std;

void solve();

int main() {
int t;
cin >> t;
for (int i = 0; i != t; ++i) {
cout << "case #" << i << ":\n";
solve();
}
}

void solve() {
static double frequencies[26];
for (auto &f : frequencies) {
cin >> f;
}

static char str[101];
cin >> str;

// 1. 频率大的在前面；如果相等，
// 2. 字母序排列；如果相等，
// 3. 小写在前面。由于 ASCII 里面小写在后面，所以反过来。
sort(str, str + strlen(str), [](char lhs, char rhs) {
auto lhs_lower = tolower(lhs);
auto rhs_lower = tolower(rhs);
return tie(frequencies[rhs_lower - 'a'], lhs_lower, rhs) <
tie(frequencies[lhs_lower - 'a'], rhs_lower, lhs);
});

cout << str << '\n';
}


char to_upper(char a){
if(a>=65&&a<=90)
return a;
else
return a-32;
}

bool cmp(char a,char b){
char upp_a = to_upper(a);
char upp_b = to_upper(b);
if(upp_a==upp_b)
return a>b;
if(m[upp_a]==m[upp_b]&&upp_a!=upp_b)
return upp_a < upp_b;
return m[upp_a]>m[upp_b];
}